How to refresh a GridView?

后端 未结 9 2298
清歌不尽
清歌不尽 2020-12-01 08:01

I have a GridView which is pretty similar to the Google tutorial, except that I want to add the ImageViews on runtime (via a subactivity). The results are okay, but the layo

9条回答
  •  爱一瞬间的悲伤
    2020-12-01 08:07

    This may be helpful. I refresh a gridview of book image thumbnails after a delete is executed on an item. Using adapter.notifyDataChanged(); as mentioned above didn't work for me as it's called in my adapter.

    //this is a call that retrieves cached data.
    //your constructor can be designed and used without it.
    final Object data = getLastNonConfigurationInstance();
    

    I essentially just reload the adapter and bind it to the same view.

    //reload the adapter
    adapter = new BooksAdapter(MyBooks.this, MyBooks.this, data, show_collection );
    grid.invalidateViews();
    grid.setAdapter(adapter);
    

提交回复
热议问题