-1

This is my code

public class ImageAdapter extends BaseAdapter {

    ImageView imageView;
    private Context context;

    public int Images[] = {Integer.parseInt(("http://www.fashionlady.in/wp-content/uploads/2016/03/creative-punjabi-mehndi-design-2016.jpg")),
            Integer.parseInt("https://lumiere-a.akamaihd.net/v1/images/uk_toystory_chi_woody_n_5b5a006f.png?region=0,0,300,300"),
            Integer.parseInt("https://lumiere-a.akamaihd.net/v1/images/open-uri20150422-20810-10n7ovy_9b42e613.jpeg"),
            Integer.parseInt("http://www.wetpaint.com/wp-content/uploads/2015/11/toy-story-20th-anniversary.jpg")};

    public ImageAdapter (Context c){
        context= c;    
    }

    @Override
    public int getCount() {
        return Images.length;
    }

    @Override
    public Object getItem(int position) {
        return Images[position];
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {    
        ImageView imageview = new ImageView(context);
        imageview.setImageResource(Images[position]);
        imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageview.setLayoutParams(new GridView.LayoutParams(240,240));

        Picasso.with(context).load(Images[position]).into(imageview);

        return imageview;
    }
}

I am trying to implement Picasso in my project the problem i am facing is I have an int array of Images .and i am getting error java.lang.NumberFormatException ,i guess its because there is no pars Int in array of Images.And if i make it String i.e public String Images[] = {("URL"),("URL"),("URL"),("URL"),("URL")};

But setimageResourcewants an int value please help me i am stuck with this .Any help would really be appreciated . Thanks.

Juan Cruz Soler
  • 7,684
  • 5
  • 34
  • 42
Frankruss
  • 35
  • 8

1 Answers1

0

Syntax from the picasso site:

 Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

Use a String[] instead of a Integer[] would be the correct solution

public String[] Images = { "http://www.fashionlady.in/wp-content/uploads/2016/03/creative-punjabi-mehndi-design-2016.jpg",
       "https://lumiere-a.akamaihd.net/v1/images/uk_toystory_chi_woody_n_5b5a006f.png?region=0,0,300,300",
       "https://lumiere-a.akamaihd.net/v1/images/open-uri20150422-20810-10n7ovy_9b42e613.jpeg",
       "http://www.wetpaint.com/wp-content/uploads/2015/11/toy-story-20th-anniversary.jpg" };

You don't need imageview.setImageResource(Images[position]);when you load the image with Picasso, so just remove that line

Denny
  • 1,586
  • 3
  • 15
  • 32
  • I have multiple Urls in images [] and u r loading a single url in picasso .I want to load the Images[] into picasso – Frankruss May 11 '17 at 14:24
  • No, I'm just quoting the syntax from the picasso site. I said that you should use a string array instead of an integer array and remove the `setImageResource` line. – Denny May 11 '17 at 14:25
  • What does that have to do with your question? – Denny May 11 '17 at 14:34
  • buddy if i remove setimageresource it doesnot sdisplay any image i get a blank screen.I guess it needs and imageresource – Frankruss May 11 '17 at 14:34
  • Because you're not inflating a view at all, look [here](http://stackoverflow.com/questions/16333754/how-to-customize-listview-using-baseadapter) or [here](http://abhiandroid.com/ui/baseadapter-tutorial-example.html) for examples – Denny May 11 '17 at 14:42
  • Thanks removing set ImageResource worked,but what to setImageResource in my Fullactivity class – Frankruss May 12 '17 at 08:17
  • I don't know what your Fullactivity class does/is/looks like – Denny May 12 '17 at 08:19
  • I solved it too by adding Picasso in Full ImageActivity class.Thanks Denny !! – Frankruss May 12 '17 at 08:34