-1
public ArrayList<String> getData()
{
ArrayList<String> listItems = new ArrayList<String>();
String result = "";
InputStream isr=null;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/get_data.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
isr = entity.getContent();
}
catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
//resultView.setText("Couldnt connect to database");
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(isr,"iso- 8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
isr.close();
result=sb.toString();
}
catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
//parse json data
try {
String s = "";
JSONArray jArray = new JSONArray(result);
for(int i=0; i<jArray.length();i++)
{
JSONObject json=jArray.getJSONObject(i);
listItems.add(json.getString("name"));
listItems.add(json.getString("ph.no"));
listItems.add(json.getString("id"));
// adding HashList to ArrayList
}
// resultView.setText(s);
} catch (Exception e)
{
// TODO: handle exception
Log.e("log_tag", "Error Parsing Data "+e.toString());
}
return listItems;
// selecting single ListView item
}
我正在开发一个名为电话簿的Android应用程序。我从服务器提取人员的详细信息 作为json对象。在Android上显示详细信息Json对象在列表视图上显示
我能够显示特定人员在不同行中的联系人详细信息。如何在同一行显示单个人的详细信息。
为此,你将不得不使用定制的ListView。 –
可以使用[BaseAdapter](http://developer.android.com/reference/android/widget/BaseAdapter.html)将数据加载到listview [示例](http://anujarosha.wordpress.com/2011/11/30 /如何使用的-baseadapter和 - onitemclicklistener功能于机器人/) –