I’m trying to use in my Android Application the notifyDataSetChanged() method for an ArrayAdapter but it doesn’t work for me.
I found as answer here, that notifyDataSetChanged() should run in the main thread, but there was no example for that.
Could anybody send an example or at least a link?!
For an
ArrayAdapter,notifyDataSetChangedonly works if you use theadd(),insert(),remove(), andclear()on the Adapter.When an
ArrayAdapteris constructed, it holds the reference for theListthat was passed in. If you were to pass in aListthat was a member of an Activity, and change that Activity member later, theArrayAdapteris still holding a reference to the originalList. The Adapter does not know you changed theListin the Activity.Your choices are:
ArrayAdapterto modify the underlying List (add(),insert(),remove(),clear(), etc.)ArrayAdapterwith the newListdata. (Uses a lot of resources and garbage collection.)BaseAdapterandListAdapterthat allows changing of the underlyingListdata structure.notifyDataSetChanged()every time the list is updated. To call it on the UI-Thread, use therunOnUiThread()ofActivity.Then,
notifyDataSetChanged()will work.