android - notifyDataSetChanged example -
i'm trying use in android application notifydatasetchanged() method arrayadapter doesn't work me.
i found as answer here, notifydatasetchanged() should run in main thread, there no example that.
could send example or @ least link?!
for arrayadapter, notifydatasetchanged works if use add(), insert(), remove(), , clear() on adapter.
when arrayadapter constructed, holds reference list passed in. if pass in list member of activity, , change activity member later, arrayadapter still holding reference original list. adapter not know changed list in activity.
your choices are:
- use functions of
arrayadaptermodify underlying list (add(),insert(),remove(),clear(), etc.) - re-create
arrayadapternewlistdata. (uses lot of resources , garbage collection.) - create own class derived
baseadapter,listadapterallows changing of underlyinglistdata structure. - use
notifydatasetchanged()every time list updated. call on ui-thread, userunonuithread()ofactivity. then,notifydatasetchanged()work.
Comments
Post a Comment