5

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;
        }
    });
SoliQuiD
  • 2,093
  • 1
  • 25
  • 29
  • That cant be, all touch actions begins with a action_down, then many action_move until the Action_up finishes the touch. – Nanoc Nov 25 '15 at 15:21
  • @nanoc thanks ofr trying to help, but i found the solution and wrote it – SoliQuiD Nov 25 '15 at 15:23

1 Answers1

8

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;
}

}

SoliQuiD
  • 2,093
  • 1
  • 25
  • 29