views:

185

answers:

2

What does the method adapter.notifyDataSetInvalidated() accomplish? There is no documentation on it.

I am trying to reload a ListView and notifyDataSetChanged or notifyDataSetInvalidated don't seem to accomplish anything.

+1  A: 

It depends on the adapter implementation... if you take a look of the source code you will see that:

  1. notifyDataSetInvalidated() calls the notifyInvalidated() of the DataSetObservable class (see here)
  2. Then, notifyInvalidated() calls the onInvalidated() method for each DataSetObserver (see here).
  3. Then comes the funny part: onInvalidated() does not do anything...

This is its implementation:

public void onInvalidated() {
    // Do nothing
}

DataSetObserver is an abstract class, so it's up to the subclass to decide what to do on onInvalidated().

Cristian
+1  A: 

afaik the notifyDataSetInvalidated() stops the adapter from accessing the data in case its invalid or gone or something. notifyDataSetChanged() updates the ListView so you can see the new data added but you have to call it in the UI thread.

It helped me a lot to watch http://www.youtube.com/watch?v=wDBM6wVEO70 there are 2 sections where they mention those methods and explain how to use them correctly. Maybe it helps you too :)

Exception