My problem is that all touch events are being detected but not the Action_Down event. the log results in events 1, 2 and not 0 (for down).
here is my code
final ViewPager homeViewPager = (ViewPager)findViewById(R.id.homeViewPager);
homeViewPager.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch (View v, MotionEvent event){
Log.i("ViewPager", "event " + event.getAction());
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
Log.i("ViewPager", "ACTION_MOVE");
break;
case MotionEvent.ACTION_DOWN:
Log.i("ViewPager", "ACTION_DOWN");
break;
case MotionEvent.ACTION_UP:
Log.i("ViewPager", "ACTION_UP ");
break;
}
return false;
}
});
I found a good explanation on http://neevek.net/posts/2013/10/13/implementing-onInterceptTouchEvent-and-onTouchEvent-for-ViewGroup.html
simply: viewpager is a viewgroup so by default it passes its (down) touch events to child views
solution i override the class with this and used my viewpager class
public class MyViewPager extends ViewPager {
public MyViewPager(Context context) {
super(context);
}
public MyViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return true;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With