Skip to content Skip to sidebar Skip to footer

How To Disable Swipes In A View Pager In Android

I am new to android. I am creating an app which consists of a view pager with a swipe tab layout. When I click the button it does some calculations inside of the view pager. While

Solution 1:

public class CustomViewPager extends ViewPager {

private boolean enabled;

public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.enabled = true;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.enabled) {
    return super.onTouchEvent(event);
}

return false;
}

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.enabled) {
    return super.onInterceptTouchEvent(event);
}

return false;
}

public void setPagingEnabled(boolean enabled) {
this.enabled = enabled;
} }

You just need to call the "setPagingEnabled" method with "false" and users won't be able to swipe to paginate.


Post a Comment for "How To Disable Swipes In A View Pager In Android"