Android 如何将毕加索传递到listView适配器

Android 如何将毕加索传递到listView适配器,android,android-listview,picasso,Android,Android Listview,Picasso,我需要将这一行传递到列表适配器 Picasso.with(getActivity()).load(imageurl).into(imageOrders); 名单 我是一个乞丐,我试了很多,但我想不出来,请帮助我,你不能把毕加索传给适配器。您必须创建自己的自定义适配器,这并不像听起来那么令人畏惧。它甚至可能基于SimpleAdapter。像这样: public class MyAdapter extends SimpleAdapter{ public MyAdapter(Context

我需要将这一行传递到列表适配器

Picasso.with(getActivity()).load(imageurl).into(imageOrders);
名单

我是一个乞丐,我试了很多,但我想不出来,请帮助我,你不能把毕加索传给适配器。您必须创建自己的自定义适配器,这并不像听起来那么令人畏惧。它甚至可能基于SimpleAdapter。像这样:

public class MyAdapter extends SimpleAdapter{

   public MyAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to){
      super(context, data, resource, from, to);
}

   public View getView(int position, View convertView, ViewGroup parent){
      // here you let SimpleAdapter built the view normally.
      View v = super.getView(position, convertView, parent);

      // Then we get reference for Picasso
      ImageView img = (ImageView) v.getTag();
      if(img == null){
         img = (ImageView) v.findViewById(R.id.imageOrders);
         v.setTag(img); // <<< THIS LINE !!!!
      }
      // get the url from the data you passed to the `Map`
      String url = ((Map)getItem(position)).get(TAG_IMAGE);
      // do Picasso
      Picasso.with(v.getContext()).load(url).into(img);

      // return the view
      return v;
   }
}
你不能把毕加索传给适配器。您必须创建自己的自定义适配器,这并不像听起来那么令人畏惧。它甚至可能基于SimpleAdapter。像这样:

public class MyAdapter extends SimpleAdapter{

   public MyAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to){
      super(context, data, resource, from, to);
}

   public View getView(int position, View convertView, ViewGroup parent){
      // here you let SimpleAdapter built the view normally.
      View v = super.getView(position, convertView, parent);

      // Then we get reference for Picasso
      ImageView img = (ImageView) v.getTag();
      if(img == null){
         img = (ImageView) v.findViewById(R.id.imageOrders);
         v.setTag(img); // <<< THIS LINE !!!!
      }
      // get the url from the data you passed to the `Map`
      String url = ((Map)getItem(position)).get(TAG_IMAGE);
      // do Picasso
      Picasso.with(v.getContext()).load(url).into(img);

      // return the view
      return v;
   }
}

我发现我的代码中有一个lil细节错误,请检查编辑,我用一个箭头指出:“我确实使用了youre以前的代码,但删除了以Stringurl开头的行,并将其加载(“来自JSONObject(imagelink)的字符串”)对于1个列表项,它是有效的,因为现在我在列表中只有一个项目,我会检查,然后另一个人会将更多列表项添加到jsonSo中,我如何才能将所有这些添加到活动中?我发现我的代码中有一个lil详细信息错误,请检查编辑,我用如下箭头指向:我确实使用了youre以前的代码,但删除了以Stringurl开头的行,并将load(“来自JSONObject(imagelink)”的字符串)和它用于1个列表项,因为现在我在列表中只有一个项,将检查,然后另一个人将向jsonSo添加更多列表项,我如何在活动中添加所有这些?
ListView list= (ListView) getActivity().findViewById(R.id.list);
ListAdapter adapter = 
       new MyAdapter(
                getActivity(),
                orderList,
                R.layout.order_usa_row,
                new String[]{TAG_PRICE,TAG_TITLE,TAG_PSTATUS,TAG_PRICESYMBOL},
                new int[]{R.id.price,R.id.title,R.id.pstatus,R.id.symbol});
list.setAdapter(adapter);