当前位置: 编程技术>移动开发
本页文章导读:
▪做了一个可以查询飞机航班、列车班次的小应用 做了一个可以查询飞机航班、火车班次的小应用
做得很粗糙,代码量也很少,数据通过调用web service得到。TrainActivity.java用于输入起点站、终点站,并将输入的值传入下一个Activitypackage cn..........
▪ xcode4.2 批改_MyCompanyName_ xcode4.2 修改__MyCompanyName__
修改工程的属性:Organization 属性,见下图:
看到Organization这一栏了吧,修改成你公司的名称即可,
打开这一菜单的快捷键是 command + alt+ 1 用windows键.........
▪ xcode的运行环境只有My Mac b4-bit的解决办法 xcode的运行环境只有My Mac b4-bit的解决方法
在Edit Scheme里,Executable对应的下拉列表里选择当前的app
......
[1]做了一个可以查询飞机航班、列车班次的小应用
来源: 互联网 发布时间: 2014-02-18
做了一个可以查询飞机航班、火车班次的小应用
做得很粗糙,代码量也很少,数据通过调用web service得到。
TrainActivity.java用于输入起点站、终点站,并将输入的值传入下一个Activity
ListTrainActivity.java用于显示所有的查询出来的火车航班,通过dom4j来解析xml
飞机航班的做法很类似,下面上效果图
做得很粗糙,代码量也很少,数据通过调用web service得到。
TrainActivity.java用于输入起点站、终点站,并将输入的值传入下一个Activity
package cn.salesuite.layout;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
/**
* @author Tony Shen
*
*/
public class TrainActivity extends Activity{
int REQUEST_CODE=2;
Button queryButton; //查询按钮
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
setTitle("火车班次查询");
super.onCreate(savedInstanceState);
setContentView(R.layout.train);
queryButton = (Button) findViewById(R.id.query);
queryButton.setOnClickListener(queryListener);
}
// query按钮监听器
OnClickListener queryListener = new OnClickListener() {
public void onClick(View v) {
CharSequence firstStationValue = ((EditText) findViewById(R.id.firstStation)).getText();
CharSequence lastStationValue = ((EditText) findViewById(R.id.lastStation)).getText();
String temp = firstStationValue.toString() + "," + lastStationValue.toString();
Intent intent = new Intent(TrainActivity.this, ListTrainActivity.class);
intent.setData(Uri.parse(temp));
startActivityForResult(intent, REQUEST_CODE);//以传递参数的方式跳转到下一个Activity
}
};
}ListTrainActivity.java用于显示所有的查询出来的火车航班,通过dom4j来解析xml
package cn.salesuite.layout;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpProtocolParams;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
/**
* @author Tony Shen
*
*/
public class ListTrainActivity extends Activity {
private List<Map<String, Object>> data;
private ListView listView = null;
SimpleAdapter adapter = null;
String responseBody = null;
Intent intent;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
setTitle("个人生活助理beta");
super.onCreate(savedInstanceState);
listView = new ListView(this);
intent=ListTrainActivity.this.getIntent();
String tmp=intent.getDataString();
String[] stations= tmp.split(",");
try {
responseBody = parseTrain(stations[0], stations[1]);
} catch (Exception e) {
e.printStackTrace();
}
PrepareData(responseBody);
// 利用系统的layout显示一项
SimpleAdapter adapter = new SimpleAdapter(this, data,
R.layout.train_row, new String[] { "TrainCode", "FirstStation","LastStation", "StartTime", "ArriveTime" },
new int[] {R.id.text1, R.id.text2, R.id.text3, R.id.text4,R.id.text5 });
listView.setAdapter(adapter);
setContentView(listView);
OnItemClickListener listener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
setTitle(parent.getItemAtPosition(position).toString());
}
};
listView.setOnItemClickListener(listener);
}
protected String parseTrain(String firstStation, String lastStation)
throws Exception {
String url = "/WebServices/TrainTimeWebService.asmx/getStationAndTimeByStationName";
String host = "www.webxml.com.cn";
String param = "StartStation="
+ URLEncoder.encode(firstStation, "utf-8") + "&ArriveStation="
+ URLEncoder.encode(lastStation, "utf-8") + "&userID=";
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(
HttpProtocolParams.HTTP_CONTENT_CHARSET, "UTF-8");
HttpGet httpget = new HttpGet("http://" + host + url + "?" + param);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
return httpclient.execute(httpget, responseHandler);
}
private void PrepareData(String responseBody) {
data = new ArrayList<Map<String, Object>>();
Map<String, Object> item;
Document document;
try {
document = DocumentHelper.parseText(responseBody);
Element root = document.getRootElement();
Iterator it = root.element("diffgram").element("getStationAndTime").elementIterator("TimeTable");
while (it.hasNext()) {
Element info = (Element) it.next();
item = new HashMap<String, Object>();
item.put("TrainCode", info.elementText("TrainCode"));
item.put("FirstStation", info.elementText("FirstStation"));
item.put("LastStation", info.elementText("LastStation"));
item.put("StartTime", info.elementText("StartTime"));
item.put("ArriveTime", info.elementText("ArriveTime"));
data.add(item);
}
} catch (DocumentException e) {
e.printStackTrace();
}
}
}飞机航班的做法很类似,下面上效果图
[2] xcode4.2 批改_MyCompanyName_
来源: 互联网 发布时间: 2014-02-18
xcode4.2 修改__MyCompanyName__
修改工程的属性:Organization 属性,见下图:
看到Organization这一栏了吧,修改成你公司的名称即可,
打开这一菜单的快捷键是 command + alt+ 1 用windows键盘是 win + alt+1
或者选择工程上文件,然后点击xcode左上方的打开右边属性栏的按钮,可以看到工程属性视图,如上图上见
[3] xcode的运行环境只有My Mac b4-bit的解决办法
来源: 互联网 发布时间: 2014-02-18
xcode的运行环境只有My Mac b4-bit的解决方法
在Edit Scheme里,Executable对应的下拉列表里选择当前的app
在Edit Scheme里,Executable对应的下拉列表里选择当前的app
最新技术文章: