0

i need to pass this line into the list adapter

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

List

ListView list= (ListView) getActivity().findViewById(R.id.list);
ListAdapter adapter=new SimpleAdapter(getActivity(),orderList,R.layout.order_usa_row,
new String[]{TAG_PRICE,TAG_TITLE,TAG_PSTATUS,TAG_PRICESYMBOL,TAG_IMAGE},new int[]{R.id.price,R.id.title,R.id.pstatus,R.id.symbol,R.id.imageOrders});

list.setAdapter(adapter);

i'm a begginer, i tried a lot but i can't figure it out , please help

Alex
  • 49
  • 9

1 Answers1

5

you can't "pass Picasso" to the adapter. You have to create your own custom adapter, it's not as daunting as it sounds. It may even be based on the SimpleAdapter. Like this:

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;
   }
}

then you can just use this class without the image on the parameters (but it must still exist inside orderList).

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);
Budius
  • 39,391
  • 16
  • 102
  • 144
  • I found a lil detail wrong on my code, please check the edit, I pointed with an arrow like this: "<<< THIS LINE" – Budius Sep 30 '14 at 12:25
  • i did use youre previous code but deletete the line Starting with Stringurl , and put load("the string from JSONObject(imagelink)")and it worket for 1 list item , for now i have only one item in the list, will check then the other guy will add more list items into json – Alex Sep 30 '14 at 18:32
  • So, how can i add all this in the activity ? https://stackoverflow.com/questions/55860377/set-image-url-into-listadapter-to-show-images-using-picasso – user3099225 Apr 26 '19 at 03:49