Improve ListView efficiency when loading images from SD into the ListView

前端 未结 2 931
深忆病人
深忆病人 2021-01-07 14:14

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 jp

相关标签:
2条回答
  • 2021-01-07 14:34

    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);
    }
    
    0 讨论(0)
  • 2021-01-07 14:39

    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

    0 讨论(0)
提交回复
热议问题