【问题标题】:List showing the last item in the ArrayList显示 ArrayList 中最后一项的列表
【发布时间】:2013-11-12 17:04:32
【问题描述】:

我有一个简单的问题。为什么这个列表显示列表中的最后一项

感谢任何答案...

    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);

【问题讨论】:

  • 不清楚你在这里问什么

标签: android list hashmap


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    在第二个代码块中,您使用的是 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多