Reputation: 6501
My application has a ListView
.
The ListView
has lots of images.
1) What is the best/most efficient way to preload these images into my ListView
? (I am setting the images in bindView()
of SimpleCursorAdapter
). Should I store them as assets, raw files or in the drawable directory?
If I store my images in drawable
, I basically have their name but not the int
resource.
2) Is getIdentifier()
the way to go here?
The application queries the server if a new set of images are available. If they are available it lazy downloads them and stores them into the cache. Now the old images are useless.
3) Is there any way to get rid of them?
Upvotes: 0
Views: 901
Reputation: 2172
I suggest you to try Picasso.It takes care of handling cache and image loading.
In the getView method of the Adapter class, all you need is one line of code.
Picasso.with(context).load(image_url).into(holder.imageView);
Upvotes: 1
Reputation: 364
What is the best/most efficient way to preload these images into my ListView?
You are already using LazyList so that's perfetct
Should I store them as assets, raw files or in the drawable directory?
That depends on your choice
Is there any way to get rid of them?
yeah go to the FileCache class in lazylist,that in there there would be a variable cacheDir
which actually tells you the directory where the older/cached images are stored and hence you can perform whatever you want to,from there
Edit: here is the link for lazylist https://github.com/thest1/LazyList
what it does is,it downsamples the images before loading into the iamgeview hence saving a lot of memory,i guess it uses viewholder pattern and hence nothing to worry about memory leaks also it loads images asynchronously and hence UI doesn't lag for the time images are being loaded
Upvotes: 0