Reputation: 202
I am using a custom adapter for my ListView as per the efficient adapter sample by Romain Guy.
In the getView() method of my adapter I am assigning an ImageView a jpg image stored on SD using the following code :
File f=new File(MovieThumbs.get(position));
if(f.length() > 0) {
holder.thumb.setImageBitmap(BitmapFactory.decodeFile(MovieThumbs.get(position)));
}
When flicking through a list of some 200 items using this method the app suffers from bad stuttering as it tries dealing with the images.
Is there a more efficient solution for this?
Upvotes: 1
Views: 2912
Reputation: 43412
Images need to be processed in background thread. Recycled views need to be taken into account. I try to address all these issues in my sample code, it works fine now, you may take a look Lazy load of images in ListView
Upvotes: 0
Reputation: 8176
Rather than loading the images from within the list adapter on demand how about kicking off a thread from the onCreate of your activity to load images? As each image loads you can fire a callback to the activity to display the image in the list. The callback method would be something along the lines of:
void onImageDownloadComplete(int pos, BitMap bm) {
ListView lv = getListView();
View listItem = lv.getChildAt(pos);
ImageView img = (ImageView)listItem.getChildAt(indexOfIcon);
img.setImageBitmap(bm);
}
Upvotes: 1