Java 指定ArrayList的额外位置
我有一个HashMaps的ArrayList,我正试图将其放入详细列表视图的意图中。我已成功地在ListView中检索到ArrayList,但仍无法找到ArrayList的正确位置Java 指定ArrayList的额外位置,java,android,arrays,json,Java,Android,Arrays,Json,我有一个HashMaps的ArrayList,我正试图将其放入详细列表视图的意图中。我已成功地在ListView中检索到ArrayList,但仍无法找到ArrayList的正确位置 // declarations JSONArray comments_data = null; ArrayList<HashMap<String, String>> comments_list; // storing the values for (int z=0; z <
// declarations
JSONArray comments_data = null;
ArrayList<HashMap<String, String>> comments_list;
// storing the values
for (int z=0; z < comments_data.length(); z++)
{
JSONObject cd = (JSONObject)comments_data.get(z);
String commentText = cd.getString("text");
String username = cd.getJSONObject("from").getString("username");
HashMap<String, String> comments_hash = new HashMap<String, String>();
comments_hash.put("text", commentText);
comments_hash.put("from.username", username);
comments_list.add(comments_hash);
}
public void onItemClick(AdapterView<?> parent, View view, int pos, long id)
{
Intent i = new Intent();
i.putExtra("comments_list", comments_list); // HERE IS WHERE I AM HAVING THE ISSUE. I have tried comments_list.get(pos), but it crashes. The current one stores all of the values instead of getting only the values associated with the item that was clicked.
startActivity(i);
}
//声明
JSONArray注释_data=null;
ArrayList注释列表;
//存储值
对于(int z=0;z
你不能只添加额外内容,这是有限制的。为此,您可能需要创建一个包含hashmap的parcelable类,然后使用putParcelableArrayListExtra@zgc7009你能再详细说明一下吗?Android只支持传递原语和一些复杂的数据类型。他们不喜欢传递大量的项(HashMaps的ArrayList称之为)。您需要创建一个类,比如MyHashMap,它扩展了Parcelable,这样您就可以将您的HashMap打包成压缩数据,您的应用程序很乐意将其打包传递。在设置变量ArrayList comments\u list之后,您可以通过执行类似于putParcelableArrayListExtra(“comments\u list”,comments\u list;