when I use listview, I extends ArrayAdapter and I store the data(one list) in ArrayAdapter, so when data changed,I call:
adapter.add(item).;
And there is another choice ,store the data in my List and when data changed, called in MyAdapter.java :
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
which is the best choice?
off course adapter.add(item);
and after that call notifyDataSetChanged()
is the better way rather than initialize new adapter and set it again. but it will only works when we are working with a same list and adding or removing some elements. when we are changing the whole list it will not work at that time we should use list.addall(nList).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With