user3277633
user3277633

Reputation: 1923

Using Picasso with ImageView

I'm looking through the Grid View doc, and I wanted to see if I can display images from online instead of the ones in the local res directory.

I set up Picasso based on the doc, and decided to try to implement Picasso into imageView like so (the code below is taken from the GridVIew doc example)

public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {
            // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(300, 300));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);
        } else {
            imageView = (ImageView) convertView;
        }

        //imageView.setImageResource(mThumbIds[position]);
        Picasso.with(mContext).load("https://i.sstatic.net/E5w9Z.jpg").into(imageView);
        return imageView;
    }

I wanted this should return to me this picture to try it out, but it on my device it's not returning any images.

What am I doing wrong?

Upvotes: 0

Views: 73

Answers (1)

Bundeeteddee
Bundeeteddee

Reputation: 724

Maybe its time to do more debugging. As least it seems like the url does point to a valid image. So, maybe try some other things to figure out what is happening under the hood. For example:

  • Ensure you have set the proper permission. <uses-permission android:name="android.permission.INTERNET" />
  • Set an error view holder to see request has come back and there is an error Picasso.with(mContext).load("http://i.imgur.com/DvpvklR.png").error(R.drawable.error_holder).into(imageView);
  • Enable debug indicator for Picasso. From documentation:

For development you can enable the display of a colored ribbon which indicates the image source. Call setIndicatorsEnabled(true) on the Picasso instance.

Upvotes: 1

Related Questions