我必须根据ArrayAdapter
收到的JSON
回复进行定制。这是我的代码,我从中得到响应并将其简化ArrayAdapter
为android.R.layout.simple_list_item_1
ListView lv = (ListView) findViewById(R.id.list);
try {
HttpClient hClient = new DefaultHttpClient();
HttpGet hGet = new HttpGet(
"API HERE");
ResponseHandler<String> rHandler = new BasicResponseHandler();
data = hClient.execute(hGet, rHandler);
JSONObject rootObj = new JSONObject(data);
JSONObject searchObj = rootObj.getJSONObject("searchdata");
JSONArray titlesObj = searchObj.getJSONArray("titles");
JSONArray descsObj = searchObj.getJSONArray("desc");
JSONArray linksObj = searchObj.getJSONArray("links");
String[] a = new String[titlesObj.length()];
String[] b = new String[descsObj.length()];
String[] c = new String[linksObj.length()];
for (int i = 0; i < titlesObj.length(); i++) {
String title = titlesObj.getString(i);
a[i] = title;
}
for (int i = 0; i < descsObj.length(); i++) {
String desc = descsObj.getString(i);
b[i] = desc;
}
for (int i = 0; i < linksObj.length(); i++) {
String link = linksObj.getString(i);
c[i] = link;
}
ArrayList<String> al = new ArrayList<String>();
for (int i = 0; i < linksObj.length(); i++)
{
al.add(" " + a[i] + " " + b[i] + "" + c[i] + "");
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
MainActivity.this, android.R.layout.simple_list_item_1, al);
lv.setAdapter(adapter);
} catch (Exception e) {
}
这是我的观点的截图:
我想显示一个视图,其中三个TextView
标题为标题,另一个为 URL,最后一个为描述。
任何帮助将不胜感激。