adding item to listView after passing info through an intent in Android

前端 未结 2 806
旧时难觅i
旧时难觅i 2021-01-26 16:31

I am trying to add an item, first by using an add button, then going to a different activity, then coming back to the original one and adding it in a listview. I can\'t seem to

2条回答
  •  走了就别回头了
    2021-01-26 17:07

    First, Hashmap is suppose to be a collection, it seems you need only a pair of object, which, Map.Entry is far better solution (or even better, use a custom inner class).

    Second, you add the item each time the addScreen Activity is created, and each time it is created, your painItems are freshly created. That's the reason you see only first content there, you need to have some way to persist your list (at least within application life cycle). Quick fix (though may not be desirable) is to put static:

    private static List> painItems = ....
    

    should do the trick.

提交回复
热议问题