简体   繁体   中英

Disable swiping in ViewPager

Since few days I tried to disable the SWIPE. I read so many conversations at stackoverflow, but all this didn't work or was too old. I have a next Button . Only with the next Button the User should Come to the next Layout without swiping.

So have anybody a solution to disable swiping?

In order to get something like this working, you will need to create your own subclass of ViewPager.

It should have a new field: eg

private boolean swipeEnabled;

You will also need to override onInterceptTouchEvent and onTouchEvent and check if the user has currently enabled / disabled the ViewPager .

eg

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    return isEnabled && super.onInterceptTouchEvent(event);
}

Then in your code where you are hosting your ViewPager you should have an enable and disable method that change the value of that new field based on your needs.

Make sure in your xml layout you use this new class rather than the default ViewPager class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM