Skip to content Skip to sidebar Skip to footer

Android Arrayadapter Notifydatasetchanged Doesn't Work

In this code, after inserting new items to adaper, my list could not refresh and update with notifyDataSetChanged(). For example, for this line my adapter could set without any pro

Solution 1:

Change the following code:

items.add(item);
adapter.update(items);
adapter.notifyDataSetChanged();

to:

adapter.add(item);
adapter.notifyDataSetChanged();

I think this should solve your problem.

You don't need to use a list to store items in an Adapter that is extended the ArrayAdatper, because it will maintain a list of items for you.

Update:

Then try to pass a copy of your items List to your adapter. Try the following change:

adapter = new ReceivedAdapter(G.context, items);

to:

adapter = new ReceivedAdapter(G.context, new ArrayList<ReceivedItemStructure>(items));

When you pass a List instance to an ArrayAdapter via its constructor, it will hold than instance directly, means that every change you make to that List instance outside the ArrayAdapter will affect its data set as well.

Post a Comment for "Android Arrayadapter Notifydatasetchanged Doesn't Work"