Created
August 30, 2017 11:04
-
-
Save umarhussain15/b661ee44d196b1b6216fa6495b125343 to your computer and use it in GitHub Desktop.
Android: Disabling Swipes on View Pager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<SwipeDisabledViewPager | |
android:id="@+id/container" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.support.v4.view.ViewPager; | |
import android.util.AttributeSet; | |
import android.view.MotionEvent; | |
public class SwipeDisabledViewPager extends ViewPager { | |
public SwipeDisabledViewPager(Context context) { | |
super(context); | |
} | |
public SwipeDisabledViewPager(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
@Override | |
public boolean onTouchEvent(MotionEvent ev) { | |
// returning false will not propagate the swipe event | |
return false; | |
} | |
@Override | |
public boolean onInterceptTouchEvent(MotionEvent ev) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment