I recently came across this question and wanted to develop for those who are interested in programming what happens when you call notifyDataSetChanged() and notifyDataSetInvalidated() . * Short answer, go here
As @Cristian said in his answer, when you call these notification methods on your adapter, it basically calls several classes and ends the onChanged() / onInvalidated() call in the registered DataSetObserver for your adapter.
If you execute the code, you will really see that the DataSetObserver is abstract as indicated, and that the onChanged() / onInvalidated() methods are empty, waiting for the implementation to be subclassed.
If this was the end of the story, then why do Android framework developers keep telling us to call these methods if they don't do anything? It took some digging, but it turned out that a subclass of this DataSetObserver called AdapterDataSetObserver already exists, and it lives in the abstract class AdapterView (which extends with classes such as GridView and ListView ). This observer is automatically created by Android when you setAdapter() on your AdapterView and get registered on your adapter.
Here you can see all the crazy things that these methods actually do. The documentation is bad, and at first it seemed to me that I needed to register my own subclass DataSetObserver in order to get these functions, but it turns out that one of them has already been created for you.
* Something I thought might be useful: I believe that you can register more than one DataSetObserver for your adapter (in addition to the default). This will allow you to do some additional work if necessary (for example, it is possible to change the position of the progress bar with the image when loading raster images).
Tony Chan Oct 12 '11 at 0:27 2011-10-12 00:27
source share