我在适配器内使用目标时遇到了很大的麻烦。我对代码上的文档感到困惑
实现此类的对象必须具有 {@link #equals(Object)} 和 {@link #hashCode()} 的有效实现,以便在内部正确存储。还将比较此接口的实例以确定是否正在发生视图回收。建议您在适配器中使用时直接将此接口添加到自定义视图类型,以确保正确的回收行为。
我试图以这种方式使用目标:
class CustomTarget implements Target {
private ImageView imageView;
public CustomTarget(ImageView imageView) {
this.imageView = imageView;
}
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
imageView.setImageDrawable(new RoundedAvatarDrawable(bitmap));
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
imageView.setImageDrawable(errorDrawable);
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
imageView.setImageDrawable(placeHolderDrawable);
}
@Override
public boolean equals(Object o) {
return imageView.equals(o);
}
@Override
public int hashCode() {
return imageView.hashCode();
}
}
@Override
public View getView(int position, View v, ViewGroup parent) {
....
RoundedAvatarDrawable r = new RoundedAvatarDrawable(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_avatar_seahorse));
ImageCacheController.with(mContext).getPicasso().load(member.getPicture_url()).resize(100, 100).centerCrop().placeholder(r).error(r).into(new CustomTarget(viewHolder.ivAvatar));
....
}
它不起作用,图像之间随机变化