AsbListView and ListView call registerDataSetObserver() on the adapter.
 BaseAdapter.notifyDataSetChanged() does the notification to whoever is
registered with it.

Here is working code, the Running Services UI in settings, that implements a
BaseAdapter and uses notifyDataSetChanged() to tell the list view when its
contents change:

http://android.git.kernel.org/?p=platform/packages/apps/Settings.git;a=blob;f=src/com/android/settings/applications/RunningProcessesView.java;h=86457bf8b7e42b003ea64ea39762ae9927881c83;hb=HEAD#l363

On Tue, Jan 25, 2011 at 8:37 PM, Brill Pappin <[email protected]> wrote:

> I just searched the forums, and apparently this is a common problem.
>
> ListView with a custom adapter based on BaseAdapter.
> Its backed by a List object.
>
> The problem is that updating the data and calling notifyDataSetChanged();
> does nothing.
> I have modified the adapter so that ever method that is called in it prints
> itself to the console.
>
> my adapter has a method that does the update of the contents and attempts
> to notify:
>
> public void updateData(List<Event> data) {
>
>  this.data.clear();
>
>  this.data.addAll(data);
>
>  notifyDataSetChanged();
>
> }
>
>
> The problem is that after notifyDataSetChanged() is called, the list never
> calls any other methods, not even getCount().
>
> My data has changed, and i've notified ListView that it has, yet it still
> refuses to update.
>
>
> After some investigation in the OS source, I don't see where the observer
> in the list actually tells the list to update.
>
> It seems the only way to get the list to update its elements is to re-set
> the adapter on it with the new element set.
>
>
> Now I've seen many threads in the group saying that they user was doing
> something wrong... but I don't see how the notify is going to update the
> list period (change or no change).
>
>
> So, I think i'm dealing with a bug here.
>
>
> Can someone actually find the code that does the update in the ListVIew
> when adapters notifyDataSetChanged() is called?
>
>
> - Brill Pappin
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to