开发者

Help regarding asynchronous loading of images in Android GridView

开发者 https://www.devze.com 2023-04-04 03:20 出处:网络
I am new Android developer. I want to achieve the following: On a particular screen (Activity) I have a grid view with images being set onto it. I have hundreds of thumbnail images coming from a serve

I am new Android developer. I want to achieve the following: On a particular screen (Activity) I have a grid view with images being set onto it. I have hundreds of thumbnail images coming from a server via http request. Now I don't want the gridview (with 4 columns in one row) to load the images in one go. Instead I want images to be loaded one开发者_StackOverflow row at a time (4 images), with other tiles of the grid view showing progess bar. Also when only few images are displayed the user should still be able to scroll the gridview vertically and thereby displaying empty gridview frames or tiles but if the scrolling is paused the frames or tiles of gridview are again loaded one row at a time. I am looking for ideas to achieve this. Thanks in advance for your responses.


  1. In your Adapter's getView method set the image with a indefinite progress spinner.
  2. After that start an AsyncTask to download the image if its not present in the object returned by getItem. Pass the item's position to the asynctask.
  3. In AsyncTask's onPostExecute set the image to the view at position and hide the progress spinner.


Downloading the image in AsyncTask will ensure that your gridview is filled with items(empty) and responds to scrolling.

0

精彩评论

暂无评论...
验证码 换一张
取 消