Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ViewPager that allows disabling swiping events
public class LockableViewPager extends ViewPager {
private boolean swipeable;
public LockableViewPager(Context context) {
super(context);
}
public LockableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.swipeable = true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.swipeable) {
return super.onTouchEvent(event);
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.swipeable) {
return super.onInterceptTouchEvent(event);
}
return false;
}
public void setSwipeable(boolean swipeable) {
this.swipeable = swipeable;
}
}
@RebelRae

This comment has been minimized.

Copy link

commented Feb 22, 2017

Thanks a ton for the contribution! :*

@richardekong

This comment has been minimized.

Copy link

commented Apr 16, 2018

Thanks a billion times. it worked

@swa06

This comment has been minimized.

Copy link

commented Nov 6, 2018

Thank you @nesquena

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.