I have ViewPager and below it I have 10 buttons. By clicking on button, for example #4, the pager goes immediately to page #4 by mPager.setCurrentItem(3);. But, I want to disable the paging by swiping with finger horizontally. Thus, the paging is done ONLY by clicking on the buttons.
So, how I can disable the swiping with finger?
I have ViewPager and below it I have 10 buttons. By clicking on button,
Share
You need to subclass
ViewPager.onTouchEventhas a lot of good things in it that you don’t want to change like allowing child views to get touches.onInterceptTouchEventis what you want to change. If you look at the code forViewPager, you’ll see the comment:Here’s a complete solution:
First, add this class to your
srcfolder:Next, make sure to use this class instead of the regular
ViewPager, which you probably specified asandroid.support.v4.view.ViewPager. In your layout file, you’ll want to specify it with something like:This particular example is in a
LinearLayoutand is meant to take up the entire screen, which is whylayout_weightis 1 andlayout_heightis 0dp.And
setMyScroller();method is for smooth transition