Reputation: 43
I have some code in which I am using view pager
to display drawables. I wanted to seek drawables from parse. For this, I am using Picasso library
. I have placed Picasso.jar
file in my projects libs
folder and now I want help to implement it for my case in my class.
Here is my code:
public class ImageAdapter extends PagerAdapter {
Context context;
private int[] GalImages = new int[] {
R.drawable.one,
R.drawable.two,
R.drawable.three
};
ImageAdapter(Context context){
this.context=context;
}
@Override
public int getCount() {
return GalImages.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(R.dimen.padding_medium);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setImageResource(GalImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
I don't know where and how to use this line:
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
My goal is to fetch images from the URL in viewpager
instead of drawables.
Upvotes: 0
Views: 129
Reputation: 1255
change the GalImages
like below:
private String[] GalImages = new String[] {
"first_url","second_url","third_url"
}
load the image with picasso
like this:
Picasso.with(context).load(GalImages[position]).into(imageView);
Upvotes: 1