Android listview: adapter.add (item)? or adapter.notifyDataSetChanged ()

when I use listview, I extend the ArrayAdapter, and I store the data (one list) in the ArrayAdapter, so when the data changes, I call:

adapter.add(item).; 

And there is one more choice: to store the data in my list and when the data changes, it is called in MyAdapter.java:

  listView.setAdapter(adapter); adapter.notifyDataSetChanged(); 

which is the best choice?

+6
source share
1 answer

off course adapter.add(item); , and then calling notifyDataSetChanged() is the best way, not initializing a new adapter and repeating it. but it will work only when we work with the same list and add or remove some elements. when we change the whole list, it will not work at that time, we should use list.addall (nList).

+4
source

Source: https://habr.com/ru/post/954219/


All Articles