I have a code which shows images like a gallery using viewpager. I have in total 3 images. When the first image is being displayed i want to swipe right and show the 3rd image, whereas at this moment it is doing nothing. When the first image is displaying it goes to the 2nd image by swiping left, and so on till the third image. Now at when the third image is displaying the same problem is here, that it can go to 2nd but not to the first image at once. 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);
}
}
Sorry if i failed in explaining it clearly, i can try once more if anybody didn't understand. Thank-you.