Skip to content Skip to sidebar Skip to footer

How To Disable Viewpager Swiping Using Android-support-v4.jar In Android

I'm creating a android application with target on 2.2. I still want to use the ViewPager provided in the android.support-v4.jar.i want need to disable Viewpager swipping on button

Solution 1:

You will have to extend the view pager and create a custom view pager for you which can be used in the xml instead of the view pager that you get from support library and change some properties, see the code below, it worked for me. Use the customviewpager in your code, and the swiping will be disabled.

public class CustomViewPager extends ViewPager{

    public CustomViewPager(Context context){
        super(context);
    }

    public CustomViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev){
        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev){
        return false;
    }
}

Post a Comment for "How To Disable Viewpager Swiping Using Android-support-v4.jar In Android"