我在我的 android 项目中使用 Picasso 库。我的主要活动中有一个 ListView。所有行项都填充有来自使用 SAXParser 解析的 XML 的数据。我创建了处理列表项的自定义列表适配器。如何使用毕加索实现某种延迟加载图像。这是我的代码(自定义适配器):
public class PicassoAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public PicassoAdapter(Activity a, ArrayList<HashMap<String, String>> d)
{
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_item, null);
TextView title = (TextView) vi.findViewById(R.id.pid); // title
ImageView image = (ImageView) vi.findViewById(R.id.slika1);// slika
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);
Log.i("&&&&&&&&&&&&&&&",data.get(0).get(MainActivity.KEY_TITLE));
// Setting all values in listview
title.setText(song.get(MainActivity.KEY_TITLE));
Picasso.with(vi.getContext()).load(song.get(MainActivity.KEY_THUMB_URL)).into(image);
return vi;
}
}