我在适配器内使用Target有很大的困难。我对代码的文档感到困惑
实现该类的对象必须具有{@=(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));
....
}它不起作用,图像在彼此之间随机变化
发布于 2014-09-02 09:26:59
看来你的等价物方法坏了。您正在将图像视图与自定义目标进行比较。这可能会解决以下问题:
public boolean equals(Object o) {
if(o instanceof CustomTarget) {
return ((CustomTarget) o).imageView.equals(this.imageView);
}
return super.equals(o);
}https://stackoverflow.com/questions/20199030
复制相似问题