Skip to content Skip to sidebar Skip to footer

How To Intercept Touch Events From Viewpager.onpagechangelistener

I'm trying to disallow my ViewPager from scrolling between tabs. I have the following situation: public class MyClass extends ViewPager implements ViewPager.OnPageChangeLi

Solution 1:

This is how I handle this (my entire class) :

publicclassSelectiveViewPagerextendsViewPager {
privatebooleanpaging=true;

publicSelectiveViewPager(Context context) {
    super(context);
}

publicSelectiveViewPager(Context context, AttributeSet attributeSet){
    super(context, attributeSet);
}

@OverridepublicbooleanonInterceptTouchEvent(MotionEvent e) {
    if (paging) {
        returnsuper.onInterceptTouchEvent(e);
    }

    returnfalse;
}

publicvoidsetPaging(boolean p){ paging = p; }

}

The boolean paging gives you the option to turn this on and off, if you need it. If you don't need, just return false. If you aren't doing anything special in onTouch, you don't need to override it.

Solution 2:

Solution 3:

Your constructor doesn't get called btw. Are you creating the view pager by code or inflating it by xml? You need to define the proper constructors.

Post a Comment for "How To Intercept Touch Events From Viewpager.onpagechangelistener"