Skip to content

Instantly share code, notes, and snippets.

@dGorod
Last active July 19, 2016 09:33
Show Gist options
  • Save dGorod/7b884c76901427904a7fa7225b7fca05 to your computer and use it in GitHub Desktop.
Save dGorod/7b884c76901427904a7fa7225b7fca05 to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
/**
* Created by Dmitriy Gorodnytskiy on 24-Sep-15.
*/
public class NonSwipeableViewPager extends ViewPager {
private boolean swipe = false;
public boolean isSwipeable() {
return swipe;
}
public void setSwipeable(boolean swipe) {
this.swipe = swipe;
}
public NonSwipeableViewPager(Context context) {
super(context);
}
public NonSwipeableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
if (swipe) {
return super.onInterceptTouchEvent(arg0);
}
// Never allow swiping to switch between pages
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment