0
votes

I'm getting trouble by doing some simple task with my adapter. I've class that implementing BaseAdapter, associated to a ListView. After I've created this adapter and showed it to the user, if some event occours, I would remove all elements inside adapter, and adding new ones.

I have implement this method inside my BaseAdapter:

public void clearAndBuild(ArrayList<PictureObject> new_pics, String some_text) {
    pics.clear();
    pics.addAll(new_pics);
    this.hashtag = hashtag;

    //do something else
}

(where pics is an ArrayList containing items to put inside ListView). In my activity, fo refresh all i call:

adapter.clearAndBuild(pics, tag);
adapter.notifyDataSetChanged();

but it doesn't work. After i call that method, old items inside listView are removed, but new ones is not showed (i get an empty listview). What's wrong?

2
In your clearAndBuild call, the ArrayList you're passing is the same one you're clearing? Can't tell from the context of the code. If so, you might be clearing the new ArrayList then trying to assign it to itself.NightwareSystems
Please post your adapter and where you get the instance of it!mmlooloo

2 Answers

0
votes

the only reason could be that you are reusing the same references for pics and new_pics. Make a deep copy of new_pics before calling clear() on pics

0
votes

you can do this:

public void clearAndBuild(ArrayList<PictureObject> new_pics, String some_text) {
     pics. = new ArrayList<PictureObject>(new_pics);
     this.hashtag = hashtag;

    //do something else
}