【发布时间】:2013-12-09 13:53:40
【问题描述】:
我想从第一个 hashmap 中获取选定的行并将其显示在另一个 hashmap 中。我成功地从第一个哈希图中获取了值并将其显示在第二个哈希图中。现在的问题是如何逐个显示从第一个哈希图中选择的值,因为我目前只能在第二个哈希图中显示一个值。我通过添加条目集或 notifyDataSetChanged 进行了大量研究,但仍然无法正常工作。如我错了请纠正我。请帮忙!谢谢!
这是我的代码。 LISTMENU 是第一个 hashmap,LISTODER 是第二个 hashmap。 LISTODER 可以从 LISTMENU 的 clicktener 中获取值。
LISTMENU.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
HashMap<String, String> map = LIST2.get(position);
itemValue = map.get(FOODNAME2);
itemID = map.get(FOODID2);
Toast.makeText(getApplicationContext(),
"Food ID : " + itemID + "ListItem : " + itemValue , Toast.LENGTH_LONG)
.show();
listOrder(itemValue, itemID);
}
});
}
private void listOrder(String itemValue, String itemID)
{
ArrayList<HashMap<String, String>> LIST3 = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put(FOODID3, itemID);
map.put(FOODNAME3, itemValue);
/*for (Map.Entry<String, String> entry : map.entrySet())
{
String key = entry.getKey();
String value = entry.getValue();
}*/
LIST3.add(map);
LISTORDER = (ListView) findViewById(R.id.listOrder);
List3Adapter adapter = new List3Adapter(MainActivity.this, LIST3);
LISTORDER.setAdapter(adapter);
/*adapter.setNotifyOnChange(true);
adapter.addAll(map);
adapter.notifyDataSetChanged();*/
}
【问题讨论】:
标签: java android listview hashmap