Images were Shuffled when scrolling a ListView with a ViewHolder

前端 未结 2 1088
情歌与酒
情歌与酒 2021-01-02 11:53

My problem is connected when the user scrolls the ListView. I looked around and saw numerous examples of \'listview lazy image\', has also watched the video of the Google IO

2条回答
  •  攒了一身酷
    2021-01-02 12:40

    Your problem is that you are colling notifyDataSetChange() inside of getView method

    if(!item.get("thumbs").equals("null")){
        Drawable cacheImage = loader.loadDrawable(item.get("thumbs"), new ImageManage.ImageCallback() {
            public void imageLoaded(Drawable imageDrawable, String imageUrl) {
                ImageView imageViewByTag = (ImageView) _listView.findViewWithTag(imageUrl);
                if(imageViewByTag != null)
                    imageViewByTag.setBackgroundDrawable(imageDrawable);
            }
        });
        imageView.setImageDrawable(cacheImage);
        notifyDataSetChanged();
    }
    

    code above should be done outside of getView method.

提交回复
热议问题