protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.import_company_code_activity);
listView=(ListView)findViewById(R.id.list);
List> list=getData();
listView.setAdapter(new ListAdapter(this, list));
listView.setOnItemClickListener(new ItemClickListener());
}
方法public List> getData(){
final List> list=new ArrayList>();
new Thread(){
public void run(){
try {
String url=”http://guoqiang.x9.fjjsp01.com/factory/Get/null”;
// String url=”http://vsdemo.x9.fjjsp01.com/quality/mobile/getCustomer”;
HttpGet post=new HttpGet(url);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(post);
// 执行get请求.
// httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);
// response = httpClient.execute(post);//发送请求
Toast.makeText(getApplicationContext(), “2”, 0).show();
int statusCode=response.getStatusLine().getStatusCode();
Toast.makeText(getApplicationContext(), “3”, 0).show();
if (statusCode>= 200&&statusCode<400) {//判断请求是否成功
HttpEntity entity = response.getEntity();
String out = EntityUtils.toString(entity, “UTF-8”);
//out=Base64.encodeToString(out.getBytes(“GBK”) ,Base64.DEFAULT);
JSONArray array=new JSONArray(out);
for(int i=0 ; i
Map map=new HashMap();
JSONObject myjObject = array.getJSONObject(i);
String title = myjObject.getString(“id”);
Toast.makeText(getApplicationContext(), title, 0).show();
String info = myjObject.getString(“name”);
String code = myjObject.getString(“code”);
map.put(“title”, title);
map.put(“info”, info);
map.put(“msg”, code);
list.add(map);
}
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), “URL请求失败”, 0).show();
e.printStackTrace();
}
}
}.start();
return list;
}