Android Dev Protips! -- Why isn't NotifyDataSetChanged working?
Fun bug from this afternoon: let's say you have a custom ListAdapter you're working with to fill in data into a ListView, and you're trying to implement a method which allows you to insert a new element into that list. You're competent with the use of Adapters, so you're confident it works - in fact, the model for your add function matches most of the recommendations on StackOverflow:
So, you're confident everything is looking good, yet whenever you actually go to add the new string, the list doesn't update! It comes up when you leave and return to the activity (because you're properly serializing elsewhere in code), but it won't update on the spot.
So you go hunting further into StackOverflow to see if there was something subtle you missed about how to hook up a ListAdapter properly in your ListFragment. Maybe using setListAdapter doesn't properly set up your fragment's ListView as an observer for the adapter? That wouldn't make much sense, but you aren't sure. Perhaps it was something else...
Regardless, you spend a few hours hunting, and nothing comes up. All the errors with NotifyDataSetChanged are pretty dumb errors regarding simply misusing the class, which you've confirmed many times over by now that you haven't done.
So what's the problem?
Well, in case you had the same issues I did this afternoon, it may be that you accidentally let Eclipse fill in your functions for you, so among them you overwrote registerDataSetObserver and unregisterDataSetObserver, and they're filled in with TODO messages rather than calling the superclass's versions. WHOOPS.
The fix: delete those functions, dummy - you're not doing anything in there anyway!










