Skip to content

Instantly share code, notes, and snippets.

@gouravd
Created December 5, 2014 08:47
Show Gist options
  • Save gouravd/66ccfbbe71fe17171c92 to your computer and use it in GitHub Desktop.
Save gouravd/66ccfbbe71fe17171c92 to your computer and use it in GitHub Desktop.
Disable Swiping in ViewPager
/****
*** use this class NonSwipeableViewPager instead of the standard ViewPager
****/
package com.groupshoppy.helpers;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class NonSwipeableViewPager extends ViewPager {
public NonSwipeableViewPager(Context context) {
super(context);
}
public NonSwipeableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
// Never allow swiping to switch between pages
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// 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