Improve ListView efficiency when loading images from SD into the ListView

前端 未结 2 933
深忆病人
深忆病人 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);
    }
    

提交回复
热议问题