Search code examples
androidlistviewandroid-listview

Display images in a listView


In my android App, I have a lot of ListView. For each item of a listView, I have a TextView, and an ImageView.

I use Adapter for display items and AsynTask to download Image from server. When I scroll down my ListView, the images are downloaded. But when I scroll up, the images, which are already downloaded, download again.

I want to create a sort of cache of image, do you understand my problem ?

This is the type of my ListView : Image + TXT :

enter image description here
(source: androidhive.info)

Thanks a lot!


Solution

  • That is because you aren't caching the images. Every time the scrolled item comes back into view, you end up going to the server again for the image. Wanna save some hassle? Try Picasso.

    Many common pitfalls of image loading on Android are handled automatically by Picasso:

    Handling ImageView recycling and download cancelation in an adapter.
    Complex image transformations with minimal memory use.
    Automatic memory and disk caching.