Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 502
BollMose Avatar asked Sep 20 '13 03:09

BollMose


1 Answers

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

like image 121
Jignesh Ansodariya Avatar answered Nov 07 '22 04:11

Jignesh Ansodariya