【发布时间】:2012-03-09 17:31:33
【问题描述】:
嗨,我没有收到任何错误,但由于某种原因,它没有填写我的列表,json 提要中有一个新闻数组,里面有一个名为标题的标签,我想在列表视图中显示标题。但目前它只显示一个空白屏幕。这是我的代码
try {
// Instantiate a JSON object from the request response
JSONObject obj = new JSONObject(json);
List<String> items = new ArrayList<String>();
JSONArray jArray = obj.getJSONArray("news");
for (int i = 0; i < jArray.length(); i++) {
JSONObject oneObject = jArray.getJSONObject(i);
items.add(oneObject.getString("title"));
}
setListAdapter(new ArrayAdapter<String>(this, R.layout.single_item,
items));
ListView list = getListView();
list.setTextFilterEnabled(true);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
((TextView) arg1).getText(), 1000).show();
}
});
} catch (Exception e) {
// In your production code handle any errors and catch the
// individual exceptions
e.printStackTrace();
}
【问题讨论】:
-
请发布您尝试解析的 JSON 样本。我们不是魔术师 ;)
-
对不起,json {"code":200,"error":null,"data":{"news":[{"news_id":"8086","title":"Tickets年度最佳球员奖”,