我正在从json
文件中获取信息并在自定义中显示数据ListView
。现在,我有一个Array
名为authors
. 作者是多个。但是,在ListView
我只能看到最后一个作者姓名或最后一个数组项。如何显示所有项目?这是我的代码
for (int index = 0; index < jsonArray.length(); index++)
{
HashMap<String, String> temp = new HashMap<String,String>();
JSONObject jsonObject = jsonArray.getJSONObject(index);
String topic = jsonObject.getString("topic");
String type = jsonObject.getString("type");
String title = jsonObject.getString("title");
String absData = jsonObject.getString("abstract");
JSONArray getAuthorsArray = new JSONArray(jsonObject.getString("authors"));
for(int a =0 ; a < getAuthorsArray.length(); a++){
JSONObject getJSonObj = (JSONObject)getAuthorsArray.get(a);
String authordName = getJSonObj.getString("name");
Log.e("Name", authordName);
temp.put(KEY_AUTHOR, authordName);
}
temp.put(KEY_TOPIC, topic);
temp.put(KEY_TYPE, type);
temp.put(KEY_TITLE, title);
temp.put(KEY_ABSTRACT,absData);
list.add(temp);
}
}
simpleAdapter = new SimpleAdapter(this, list, R.layout.abstract_items, from, new int[]{R.id.abTopic,R.id.abType,R.id.abTitle,R.id.SubTitle});
setListAdapter(simpleAdapter);