android - notifyDataSetChanged() not working for custom adapter -


i have went through many similar question still not getting answer.

i using custom adapter having arraylist listview when there change on seek bar arraylist modified , want show changes on listview, doig in following 2 ways

lv = (listview) findviewbyid(r.id.lv_showcontactlist);     customadapter = new contactlistviewadapter(this);     customadapter.setlist(contactlist);     lv.setadapter(customadapter);     contactlist_temp = new arraylist<contactbean>(contactlist); 

attempt 1)

public void onprogresschanged(seekbar seekbar, int progress,         boolean fromuser) {     (contactbean object : contactlist_temp) {         int sal = integer.parseint(object.getsalary());         if (sal > progress) {             contactlist.remove(object);         }      }      customadapter.notifydatasetchanged();     contactlist.clear();     contactlist.addall(contactlist_temp); }  

attempt 2)

public void onprogresschanged(seekbar seekbar, int progress,         boolean fromuser) {     contactlist.clear();      (contactbean object : contactlist_temp) {         int sal = integer.parseint(object.getsalary());         if (sal < progress) {             contactlist.add(object);                         }     }     customadapter.notifydatasetchanged();     contactlist.addall(contactlist_temp); } 

setlist method in adapter class:

public void setlist(arraylist<contactbean> newlist) {     this.m_contactlist = newlist;     } 

my problem both methods logically doing same task 1 method not listview remains same second method working listview reflecting changes expected. want know reason behind this.

you calling customadapter.notifydatasetchanged() before changing data of adapter. need call method after changing data of adapter.

see below edit

in attempt 1:-

code should

// customadapter.notifydatasetchanged(); // not here contactlist.clear(); contactlist.addall(contactlist_temp); customadapter.notifydatasetchanged(); // must here 

in attempt 2

code should

// customadapter.notifydatasetchanged(); // not here contactlist.addall(contactlist_temp); customadapter.notifydatasetchanged(); // must here 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -