Question

I have a ListView with an image loaded by Picasso using in my adapter getView():

if (item.getPicture().contains("http")) {
     Picasso.with(context).load(item.getPicture()).placeholder(R.drawable.default_picture).into(holder.imageView);
}

Only the first cell gets an Image the other 2 show the default_picture. When I scroll all the other cells have an image. When I scroll back to the top the 2 cells that were blank now show an Image. Has anyone ever seen this? Does anyone have an idea of how I can debug?

enter image description here

Was it helpful?

Solution

Some images are not loading because the URL is empty or does not contain "http".

The reason why you see empty cells becoming non-empty is that views are recycled. So you need to either call Picasso or set the default image for your ImageView manually in getView(), but you can never leave the ImageView untouched.

Because you only call Picasso conditionnaly without always clearing the image, then when the URL is empty or does not contain "http", your ImageView will still contain the previous image of the recycled cell.

So change your code like this:

if ((item.getPicture() != null) && item.getPicture().contains("http")) {
     Picasso.with(context).load(item.getPicture()).placeholder(R.drawable.default_picture).into(holder.imageView);
} else {
     holder.imageview.setImageResource(R.drawable.default_picture);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top