简体   繁体   中英

Is the listview recycling early? Or is Universal ImageLoader canceling in error? Or is my Logic wrong?

https://github.com/nostra13/Android-Universal-Image-Loader

It works beautifuly except for the very first item in a listview is having its image loading task canceled.

It says it Is called when image loading task was cancelled because View for image was reused in newer task

however since the view is clearly still visible, this view shouldn't be recycled yet? I am using convertView.

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        if (getItemViewType(position) == HAS_IMAGE)
        {

            if (convertView == null)
            {
                convertView = li.inflate(R.layout.item_update_pic, null);
                new UpdateWithImageWrapper(convertView, position); // this is where views are looked up and set
            }
            ((UpdateWithImageWrapper) convertView.getTag()).setMyData(data.get(position), position); // this is where the correct data is set to the views and images are set to be loaded
        }
        else
        {
            if (convertView == null)
            {
                convertView = li.inflate(R.layout.item_update, null);
                new UpdateNoImageWrapper(convertView, position);
            }
            ((UpdateNoImageWrapper) convertView.getTag()).setMyData(data.get(position), position);
        }
        return convertView;
    }

Does anyone have solution?

Edit: just wanted to add that it has the issue with all of my list views.

using ImageLoader 1.8.4

Perhaps there is a way to stop the listview from recycling so quickly?

I finally figured out the real answer. in my ImageLoadingListener()

    @Override
    public void onLoadingCancelled(String imageUri, View view) { }

I was setting the image to a image that represented a loading error. Well as it turns out, that if i do not change the image when this method is called then everything works fine.

So the real issue for me is that when the onLoadingCancelled method is called, the image has already been loaded, and setting the imageview here to a image representing a cancel overwrites a successful loading of the real image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM