BaseAdapter and Picasso issue

倾然丶 夕夏残阳落幕 提交于 2019-12-02 07:12:37

You had faced this problem becuase ListView recycle items view + Picasso calls are asynchronous ... How it can appears?

  1. You start loading with Picasso
  2. View is reused (convertView != null)
  3. You are setting holder.imageD.setImageBitmap(null);
  4. Asynchronous from point 1. is finnished

Thats why you are having wrong image loaded ...

To avoid such behaviour you need to inform Picasso loader to cancel previous request. So instead just setting image bitmap to null you have to set it via Picasso library (in else statment use):

Picasso.with(context1).load(null).placeholder(R.drawable.white).into(holder.imageD);

edit: following @Budius comments: even better solution will be cancel and set instead like:

{
  Picasso.with(context1).cancelRequest(holder.imageD);
  //holder.imageD.setImageBitmap(null); //or
  holder.imageD.setImageResource(R.drawable.white); //depends on your needs
}

This should be more efficent way as it should creates less internal objects on every getView calls.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!