Skip to content

Instantly share code, notes, and snippets.

@rana01645
Created March 3, 2019 06:32
Show Gist options
  • Save rana01645/deebdf5b7d575aa1b7e87af81df03136 to your computer and use it in GitHub Desktop.
Save rana01645/deebdf5b7d575aa1b7e87af81df03136 to your computer and use it in GitHub Desktop.
Swipe controlable viewpager
package com.trickbd.broadbandhack.ui.widgets;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import androidx.viewpager.widget.ViewPager;
/*
View pager with swipe control..
*/
public class CustomViewPager extends ViewPager {
private boolean isPagingEnabled = true;
public CustomViewPager(Context context) {
super(context);
}
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return this.isPagingEnabled && super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return this.isPagingEnabled && super.onInterceptTouchEvent(event);
}
public void setPagingEnabled(boolean b) {
this.isPagingEnabled = b;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment