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.