In my android application, I have a viewpager which have a list of imageView. Each of the view can be drawn. When I draw on it, I can still swipe to the next view from viewpager. How can I disable the paging while user start to draw on a an imageView.
Asked
Active
Viewed 6,073 times
5
-
1http://stackoverflow.com/a/7814054/3790150 – saeed Apr 02 '16 at 09:12
1 Answers
6
Add this as a class and use it in xml instead of your viewpager tag. Basically we make a customised viewpager, where we are disabling the swipeable behaviour by returning false to onInterceptTouchEvent and OnTouchEvent.
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 event) {
// Never allow swiping to switch between pages
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// Never allow swiping to switch between pages
return false;
}
}

D Agrawal
- 471
- 4
- 15
-
it work but I wanted to swipe the page in certain condition. There I placed an if statement in those two event function and return true but it doesn't work – LittleFunny Apr 02 '16 at 10:05