Reputation: 1923
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
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:
<uses-permission android:name="android.permission.INTERNET" />
Picasso.with(mContext).load("http://i.imgur.com/DvpvklR.png").error(R.drawable.error_holder).into(imageView);
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