2

I am using a ViewPager, which has two pages and it is being reused. The total count what i have is 156 pages. I want to disable left swipe for page 2. Please help me out, thanks,

Here is my code..

public class SlidePagerActivity extends FragmentActivity{
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setOnPageChangeListener(new ViewPageChangeListener(){
        // set current slide index
                AbcController.getInstance().getSlideController().setCurrentSlide(_nNextSlideIndex);
                // set Current Cycle Index
                AbcController.getInstance().getSlideController().setCurrentCycle(_nNextSlideCycle);

                // set pager index
                _mPager_in.setCurrentItem(_nNextSlideIndex);
});
}
}
2
  • What do you mean by "the control"? The ViewPager itself or something else? Apr 30, 2014 at 12:16
  • the Viewpager itself, mean the position. Apr 30, 2014 at 12:32

2 Answers 2

0

I wanted to to prevent the user to go swipe back to previous page, but didn't want the page neither to disappear (to allow him to swipe back if some condition are fulfilled).

I finally use OnPageChangeListener:

viewPager.addOnPageChangeListener(new OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            if(position < pageActuelle) {
                viewPager.setCurrentItem( pageActuelle );
                return;
            }

            pageActuelle = position;
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });    
}

Now I am forcing the user to go back to the his current page when he is swiping left. This solution was really adapted to my problem since I could display a Toast when the user tries to swipe back.

Hope it could help someone.

-1

Can you specify your problem more detailed? You can always remove all pages before the specific postion, in that case there is nothing to swipe too. (sorry cant comment)

1
  • We can navigate through the page as long as the count in the fragment. I want to disable going back to the previous slide after passing by for a particular slide (say, position 2) if the count reaches position 2 left swipe must be disabled. Apr 30, 2014 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.