Search code examples
androidarraylistandroid-arrayadapterdrawablecustom-lists

How to pass image as url into arraylist using picaso library instead of drawable resource?


arr_title,arr_description,arr_img are the array list

                arr_title.add(title);
                arr_description.add(description);
                arr_img.add(R.drawable.ic_launcher);

arr_img , here takes a static image which is working fine . But , how to get it done dynamically from an image url , so that I get to fetch image from url and pass it into this arr_img , than just drawable image .

I tried , using Picaso library , but I did not understand , how to use it in place of drawable ?

This is my ArrayAdapter

class MyClass extends ArrayAdapter {

    public MyClass(Context context, int resource, ArrayList img,ArrayList txt,ArrayList img_res) 
    {
        super(context, resource,img);

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        LayoutInflater inf=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
        convertView=inf.inflate(R.layout.post_list_design,null);

        t1=(TextView)convertView.findViewById(R.id.title_list_design);
        t1.setText(arr_title.get(position).toString());

        t2=(TextView)convertView.findViewById(R.id.desc_list_design);
        t2.setText(arr_description.get(position).toString());

        i3=(ImageView)convertView.findViewById(R.id.img_logo);
        i3.setImageResource((Integer)arr_img.get(position));


        return convertView;
    }

}

Solution

  • Try this, Its better store image URL in one String and pass the string in Load methods instead of direct passing URL. It works. For me it is working Great.

    final ImageView image = (ImageView) view.findViewById(R.id.imageView1);
                Picasso.with(getApplicationContext()).load("Image Url").into(image);