简体   繁体   中英

How to refresh android GridView

I'm doing GridView activity that first show default image, then i start a new thread for netowrk task to download image from datatbase, and i would like that after the thread is finished, the GridView will automatically refresh the images in grid.

from this question i took the following code:

ImageAdapter adapt = (ImageAdapter)gridView.getAdapter();
adapt.setBitmap(bitmaps);
adapt.notifyDataSetChanged();

which update the adapter of the grid. I'm doing this 3 lines inside the onResume() method but after the thread finish i need to call the onResume() method somehow (by pausing the activity or somthing simillar).

now if i'm moving to another acitivity (like one of the grid images) and then press the back button i can see the grid view image that i just downloaded from the database. (because it calls onPause() method and then onResume() )

Doe's anyone have a solution to this problem?

Thanks

Edit: The thread is running through AsyncTask

after the thread finish i need to call the onResume() method somehow (by pausing the activity or somthing simillar).

Rather than call onResume() by force, just move those three lines into a new method, call it refreshAdapter() . Then call refreshAdapter() inside onResume() and anywhere use you want to refresh the Adapter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM