Paveliko
Paveliko

Reputation: 53

Keep the images downloaded in the listview during scrolling

I'm developing my first app and have been reading a LOT here.

I've been trying to find a solution for the following issue for over a week with no luck. I have an Adapter that extends ArrayAdapter to show image and 3 lines of text in each row. Inside the getView I assign relevant information for the TextViews and use ImageLoader class to download image and assign it to the ImageView.

Everything works great! I have 4.5 rows visible on my screen (out of total of 20). When I scroll down for the first time the images continue to download and be assigned in right order to the list.

BUT when I scroll back the list looses all the images and start redrawing them again (0.5-1 sec per image) in correct order. From what I've been reading it's the standard list performance but I want to change it.

I want that, once the image was downloaded, it will be "sticked" to the list for the whole session of the current window. Just like in Contacts list or in the Market. It is only 20 images (6-9kb each).

Hope I managed to explain myself.

Upvotes: 2

Views: 1520

Answers (2)

theelfismike
theelfismike

Reputation: 1621

The problem here is that the ArrayAdapter is reusing the list view rows as you scroll, so as you scroll down, the top row will be reused and inserted at the bottom of the list (for performance reasons).

Your best bet here is to try to cache the images locally on your device to avoid calling the ImageLoader every time.

One pretty good library that solves this problem is ignition. It's open source and available here: https://github.com/kaeppler/ignition

Take a look at RemoteImageView for a good example of the caching mechanism.

Upvotes: 0

JafarKhQ
JafarKhQ

Reputation: 8734

you need to cache each image after download it, and each time the adapter need it check if its already downloaded get it from cache (disk or memory) otherwise download it.

at first i recommended you to read this tutorial from android dev site http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html

or use an external lib like this one https://github.com/koush/UrlImageViewHelper

Upvotes: 2

Related Questions