Android ListView and dynamically loading images from the Web

Loading images into a ListView from a resource is easy. Loading images from the Web is not as easy as you might think. If you surf around the Web, you’ll find a lot of different examples of how to do it, but unfortunately, many of these methodologies are fatally flawed, which isn’t quite apparent until you try them out. This is a quick overview of what you’re suppose to do:

  • Create a separate class to process images that need to be downloaded from the Web.
  • Pass the URL of the image to the class.
  • Use a Hash table to determine if  the image is already downloaded and therefore cached. If it’s cached, set the ImageView to the cached image, otherwise, set the ImageView to a temporary image which will be replaced once the image is downloaded.
  • Fire off a separate thread to download the image, but make sure you don’t fire off a thread for an image that is already queued up to be downloaded.
  • Once the image is downloaded, update the cache table and set the ImageView to the cached image.

I found some proof of concept code of how the theory works here: Many thanks to Fedor for providing this code.


, , , , , , , , , , , , ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: