Reputation: 4762
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);
Upvotes: 0
Views: 93
Reputation: 651
At second code block you are using hashmapNoteItem instead of 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);
Upvotes: 1
Reputation: 6179
If your question is: "Why is this List NOT showing the last item in the List"
After noteItem.add(hashmapNoteItem1);
add this line:
yourAdapter.notifyDataSetChanged();
Upvotes: 0