毕加索加载图片到错误的ImageView列表中的适配器 [英] Picasso loads pictures to the wrong imageview in a list adapter

查看:127
本文介绍了毕加索加载图片到错误的ImageView列表中的适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是毕加索这样的加载图像从服务器到一个列表视图项:

I'm loading an image from a server to a list view item using picasso like this:

public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View participantView;
    if(convertView == null) {
        participantView = inflater.inflate(R.layout.participant_item, parent, false);
    } else {
        participantView = convertView;
    }

    TextView textView = (TextView) participantView.findViewById(R.id.participantName);
    textView.setText(getItem(position).getName());
    ImageView imageView = (ImageView) participantView.findViewById(R.id.participantImage);
    String profilePic = getItem(position).getProfilePic();

    if(!profilePic.equals("None")) {
        Log.d("tom.debug", "creating picture for user: " + getItem(position).getName());
        Picasso.with(this.context)
            .load(urlToProfilePics + profilePic)
            .placeholder(R.drawable.sample_0)
            .resize(52, 52)
            .into(imageView);
    } else {
        //load the place holder into the image view
        Picasso.with(this.context).load(R.drawable.sample_0);
    }

    if(!getItem(position).isHere()) {
        imageView.setColorFilter(Color.DKGRAY, PorterDuff.Mode.MULTIPLY);
    }

    return participantView;
}

if语句,为用户真正资料图片仅触发下的调试日志。 (没有用户会得到一个值)。

不过,部分也知趣加载。

另一个有用的事实(我认为):那得上下滚动列表时的错误变化的项目

Another useful fact (I think): The items that get the bug changes when scrolling up and down the list.

我不知道我在这里失踪的东西。

I'm not sure what I'm missing here.

推荐答案

请确保您拨打的 cancelRequest 每次你即将从适配器使用毕加索在getView()..

Make sure you call the cancelRequest everytime you are about to use Picasso on a getView() from the Adapter..

// 1st: reset the imageView
Picasso.with(this.context).cancelRequest(holder.imageView); 

// 2nd start a new load for the imageView
Picasso.with(this.context).load(...).into(holder.imageView); 

原因是,你是从重用视图中的 convertView 的参数属于这是可能已经由毕加索装载另一张照片一previous行。

The reason is that the view you are reusing from the convertView parameter belongs to a previous row that was possibly already being loaded by Picasso for another picture.

使用convertView的时候,如果你刚才充气一个新的布局这是唯一真正有必要,它不会是needed..but你可以打电话总是让你的code更容易。

这篇关于毕加索加载图片到错误的ImageView列表中的适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆