BaseAdapter and Picasso issue

后端 未结 1 1331
不思量自难忘°
不思量自难忘° 2021-01-25 00:28

I am having a problem loading images in ListView from a server with Picasso.

I have a BaseAdapter that is used to fill my ListView. In this ListView some items have an i

相关标签:
1条回答
  • 2021-01-25 01:16

    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.

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