Loading...

android-developers@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: [android-developers] Re: ListView/Adapter IllegalStateException Jerry Fan Wed Apr 07 08:00:31 2010

I have a fix for this. Just set the visibility of ur ListView to Gone during
update and back to visible after update. By doing so, u can avoid the
inconsistency of ur adapter and listView item count.

On Wed, Mar 31, 2010 at 4:35 PM, ionel <[EMAIL PROTECTED]> wrote:

> I am calling notifyDataSetChanged() in update method
>
> On Mar 30, 11:36 pm, social hub <[EMAIL PROTECTED]> wrote:
> > prob u need to call notifyDataSetChanged if data is changed. See if that
> > helps
> >
> > On Tue, Mar 30, 2010 at 3:15 PM, ionel <[EMAIL PROTECTED]> wrote:
> > > I've implemented a custom ListView and  Adapter, and sometimes I
> > > receive IllegalStateException exception:” ERROR/AndroidRuntime(3575):
> > > java.lang.IllegalStateException: The content of the adapter has
> > > changed but ListView did not receive a notification. Make sure the
> > > content of your adapter is not modified from a background thread, but
> > > only from the UI thread.”
> >
> > > Here is some code example:
> >
> > > public interface BuddyChangeListener {
> >
> > >     void onChange(List<Buddy> buddys);
> >
> > > }
> >
> > > public class BuddyListView extends ListView implements
> > > BuddyChangeListener
> >
> > >   public void onChange(List<Buddy> Buddy) {
> > >     MyActivity.instance.handler.post(new Runnable() {
> > >                 public void run() {
> > >                     if (((BuddyAdapter) refreshListView.getAdapter()) !
> > > = null) {
> > >                         ((BuddyAdapter)
> > > refreshListView.getAdapter()).update(Buddy);
> > >                     }
> > >                 }
> > >             });
> > > }
> > > public class BuddyAdapter extends BaseAdapter {
> >
> > >     private List<Buddy>       buddyList;
> >
> > >     public BuddyAdapter (Context context, List<Buddy> buddyList) {
> > >         this.buddyList= buddyList;
> > >     }
> >
> > >     public void update(List<Buddy> buddyList) {
> > >         this.buddyList= buddyList;
> > >         this.notifyDataSetChanged();
> > >     }
> > > }
> >
> > > Every time when the content of the list need to be updated I run from
> > > onChange method and I use a handler to change the adapter content,to
> > > update the content from UI thread.
> >
> > > Can someone to tell me if I have made something wrong on update ?
> >
> > > Thanks.
> >
> > > --
> > > 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]<[EMAIL PROTECTED]>
> <[EMAIL PROTECTED]<[EMAIL PROTECTED]>
> >
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
> >
> > > To unsubscribe from this group, send email to android-developers+
> > > unsubscribegooglegroups.com or reply to this email with the words
> "REMOVE
> > > ME" as the subject.
>
> --
> 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]<[EMAIL PROTECTED]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
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

To unsubscribe, reply using "remove me" as the subject.