Skip to content

Instantly share code, notes, and snippets.

@afiqiqmal
Created November 1, 2017 17:03
Show Gist options
  • Save afiqiqmal/99b5d709c14257059590ab25016d3b15 to your computer and use it in GitHub Desktop.
Save afiqiqmal/99b5d709c14257059590ab25016d3b15 to your computer and use it in GitHub Desktop.
This is for to block swipe of viewpager
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
/**
* @author : hafiq on 07/02/2017.
*/
public class BlockPager extends ViewPager {
boolean block = false;
public BlockPager(Context context) {
super(context);
}
public BlockPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setBlock(boolean block) {
this.block = block;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return !block && super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
return !block && super.onTouchEvent(ev);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment