BaseAdapter和毕加索的问题 [英] BaseAdapter and Picasso issue

查看:169
本文介绍了BaseAdapter和毕加索的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,从毕加索服务器加载ListView中的图像。

I am having a problem loading images in ListView from a server with Picasso.

我有一个用于填充我的ListView一个BaseAdapter。在这ListView的某些项目有一个形象的,有些不是。

I have a BaseAdapter that is used to fill my ListView. In this ListView some items have an image and some not.

在此方法:

public View getView(final int position, View convertView, ViewGroup parent) {

我做的:

 ...

//context = Activity context;
//context1 = Context context1;
context1 = context.getApplicationContext();

 if (!photo[position].equals("")) {

    String stringurl = "http://www.blablabla.it/img/"+photo[position]+".jpg";

    Picasso.with(context1)
           .load(stringurl)
           .placeholder(R.drawable.white)
           .into(holder.imageD);
        }
 else {

    holder.imageD.setImageBitmap(null);
 }

这code的工作,但往往我看到的图像是在不同的地方,比它所属!

,你可以想像,这是非常恼人的用户..谢谢大家

as you can imagine this is very annoying for users .. Thanks everybody

推荐答案

您已经面临这个问题监守的ListView回收项目查阅毕加索调用是异步的......它如何出现?

You had faced this problem becuase ListView recycle items view + Picasso calls are asynchronous ... How it can appears?

  1. 您的开始加载与毕加索
  2. 查看被重用(convertView!= NULL)
  3. 您正在设置 holder.imageD.setImageBitmap(空);
  4. 异步从点1是finnished
  1. You start loading with Picasso
  2. View is reused (convertView != null)
  3. You are setting holder.imageD.setImageBitmap(null);
  4. Asynchronous from point 1. is finnished

这就是为什么你有错误的图像加载中...

Thats why you are having wrong image loaded ...

要避免你需要通知毕加索装载机取消previous要求这样的行为。 因此,而不是只设置图像位为空,你必须通过毕加索库设置(在其他说明书使用):

To avoid such behaviour you need to inform Picasso loader to cancel previous request. So instead just setting image bitmap to null you have to set it via Picasso library (in else statment use):

<$c$c>Picasso.with(context1).load(null).placeholder(R.drawable.white).into(holder.imageD);

编辑:以下@Budius评论:更好的解决方案将被取消,而不是设置像:

edit: following @Budius comments: even better solution will be cancel and set instead like:

{
  Picasso.with(context1).cancelRequest(holder.imageD);
  //holder.imageD.setImageBitmap(null); //or
  holder.imageD.setImageResource(R.drawable.white); //depends on your needs
}

这应该是比较有效的方法,因为它应该产生更少的内部对象的每个getView调用。

This should be more efficent way as it should creates less internal objects on every getView calls.

这篇关于BaseAdapter和毕加索的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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