我有一个用户图像的
ListView
。 一些用户有个人资料图片,我使用Picasso加载这些图片。 如果用户没有图片,则使用TextDrawable在我的listview adapter中设置他的图像,如下所示。if (picture!=null) {
Uri imageUri = Uri.parse(picture);
Picasso.with(holder.pic.getContext()).load(imageUri.toString()).fit().centerCrop().into(holder.pic);
} else {
ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT
int color = generator.getColor(userName);
String userChar = userName.substring(0, 1);
TextDrawable drawable = TextDrawable.builder()
.buildRound(userChar.toUpperCase(), color);
holder.pic.setImageDrawable(drawable);
}
问题是当我滚动列表时,有时候图片会出错,那些没有图片且应该用 TextDrawable
显示的用户会显示为另一个用户的个人资料图片。
如果我使用Picasso加载所有图片,则不会发生这种情况。是否有办法将TextDrawable对象传递到picasso中以解决此问题?或者还有其他解决方案吗?