0

I have a Simple Question.Why is this List showing the last item in the List

Any Answer Appreciated...

    List<HashMap<String, Object>> noteItem=new ArrayList<HashMap<String,Object>>();

    HashMap<String,Object> hashmapNoteItem = new HashMap<String, Object>();

    hashmapNoteItem.put("todo_check", false);
    hashmapNoteItem.put("todo_content", "added 0"); 

    noteItem.add(hashmapNoteItem);

    HashMap<String,Object> hashmapNoteItem1 = new HashMap<String, Object>();
    hashmapNoteItem.put("todo_check", true);
    hashmapNoteItem.put("todo_content", "added 1"); 

    noteItem.add(hashmapNoteItem1);
4

2 回答 2

1

在第二个代码块中,您使用的是 hashmapNoteItem 而不是 hashmapNoteItem1:

List<HashMap<String, Object>> noteItem=new ArrayList<HashMap<String,Object>>();

HashMap<String,Object> hashmapNoteItem = new HashMap<String, Object>();

hashmapNoteItem.put("todo_check", false);
hashmapNoteItem.put("todo_content", "added 0"); 

noteItem.add(hashmapNoteItem);

HashMap<String,Object> hashmapNoteItem1 = new HashMap<String, Object>();
// changed hashmapNoteItem to hashmapNoteItem1
hashmapNoteItem1.put("todo_check", true);
hashmapNoteItem1.put("todo_content", "added 1"); 

noteItem.add(hashmapNoteItem1);
于 2013-11-01T17:28:08.987 回答
0

如果您的问题是:“为什么此列表未显示列表中的最后一项” 添加此行
后:noteItem.add(hashmapNoteItem1);

yourAdapter.notifyDataSetChanged();

于 2013-11-01T17:09:25.270 回答