Skip to content

Instantly share code, notes, and snippets.

@nesquena
Last active June 15, 2020 07:46
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save nesquena/898db22a38747bd9bc19 to your computer and use it in GitHub Desktop.
Save nesquena/898db22a38747bd9bc19 to your computer and use it in GitHub Desktop.
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
Copy link

Thanks a ton for the contribution! :*

@richardekong
Copy link

Thanks a billion times. it worked

@swa06
Copy link

swa06 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