tags:

views:

147

answers:

1

I'm trying to use in my Android Application the notifyDataSetChanged method for an ArrayAdapter but it doesnt'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?!

+2  A: 

You can use the runOnUiThread method as follows. If you're not using a ListActivity, just adapt the code to get a reference to your ArrayAdapter.

final ArrayAdapter adapter = ((ArrayAdapter)getListAdapter());
runOnUiThread(new Runnable() {
    public void run() {
        adapter.notifyDataSetChanged();
    }
});
Brian
I tried to add the code fragment of you in my code (you can find it here http://stackoverflow.com/questions/3667442/how-to-refresh-adapter) in onCreate-method, but I still don't have any success :( Maybe it was wrong place to adding it?!
Mur Votema
Your question just asked how you could call the method and have it run in the main UI thread. This answers that question. In your particular case (http://stackoverflow.com/questions/3670500/notifydatasetchanged-doesnt-work/3670861#3670861) AsyncTask and its onPostExecute() method seem to be what you should consider.
Brian