0

Is there a way to prevent a user swiping to the left in PagerAdapter?

When the user first enter the app they can't swipe to the left because there isn't anything there. So what if everytime you swiped to the right the left image gets destroyed and there will be nothing there like when you ran the app at first.

        @Override
        public Object instantiateItem(ViewGroup container, int position) 
        {
            Context context = MainActivity.this;

            //
            Integer highest_img = mImages.length - 1;
            Integer randomInt = getRanValue(highest_img);
            //

            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(mImages[randomInt]);

            ((ViewPager) container).addView(imageView, 0);

            return imageView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) 
        {
            ((ViewPager) container).removeView((ImageView) object);
        }
Splitme
  • 11
  • 3
  • So what is the problem if Views get destroyed as you move towards other Views in the opposite direction ? It helps with saving memory. – Rishabh Jan 30 '15 at 15:13
  • So you want to have a one way swipable viewpager? – Sam Bains Jan 30 '15 at 15:21
  • @SamBains That is exactly what i want. – Splitme Jan 30 '15 at 15:28
  • possible duplicate of [Control which directions the ViewPager can be scrolled, dynamically with UI feedback](http://stackoverflow.com/questions/13270425/control-which-directions-the-viewpager-can-be-scrolled-dynamically-with-ui-feed), and also [How to disable ViewPager from swiping in one direction](http://stackoverflow.com/questions/19602369/how-to-disable-viewpager-from-swiping-in-one-direction) – corsair992 Jan 30 '15 at 22:08

1 Answers1

0

I found a better solution for my problem.

I used the onFling() method with MotionEvent and when somebody swipe i'll just run an animation with an image replace.

Splitme
  • 11
  • 3