Question

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);
});
}
}
Was it helpful?

Solution 2

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)

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top