Daniel Gustafsson
Daniel Gustafsson

Reputation: 1817

How to update gridview with new images

adapter = new ImageAdapter(this, imagelist, imageBool, resourceName, docBool);
            adapter.NotifyDataSetChanged();
            //gridview.Adapter = null;
            gridview.InvalidateViews();
            gridview.Adapter = adapter;

I send the list with the new values to the imageadapter and it sorts the values out and returnes the items as images and alls is good. But when i want to refresh the items the old ones just stays the same and the new ones never arrives on the screen. Ive tried a lot of different ways to reload the grid but it doesn't work.

Upvotes: 1

Views: 1128

Answers (2)

Ritesh Gune
Ritesh Gune

Reputation: 16729

Add following methods to your customized adapter ie. ImageAdapter.

// Call it once , first time when you want to pass the data to adapter 
public void setImageList(List<YOUR DATA TYPE> imagelist) {
    this.imagelist = imagelist;
}

// Call this method whenever new data is to be added to existing list.
public void updateImageList(List<YOUR DATA TYPE> newImagelist) {  

    if(this.imagelist != null){
       this.imagelist.addAll(newImagelist);
    }else{
       this.imagelist = imagelist;
    }

    notifyDataSetChanged();
}

And call it once the new data is downloaded.

Upvotes: 2

lui1000
lui1000

Reputation: 89

Just create a new ImageAdapter with all the Images (including the old ones and the new ones) and assign it to the gridview. This way it works without problems. After that call

adapter.notifyDataSetChanged();

and it will work fine.

Upvotes: 1

Related Questions