How to detect a motion event when an onClick liste

2019-07-24 09:55发布

问题:

I have a ListView with onItemClick() method . Now I want to detect a touch motion in the screen . Implementing onTouchEvent() does not work in this case since I have written already a click listener . So help me how to do it. I need both the on click listener and onTouchEvent().

回答1:

You need to implement the OnTouchListener(View v, MotionEvent event) to check event.getX() and event.getY() when event.ACTION_DOWN and event.ACTION_UP and compare them to know the motion direction.

Note: you must return true to be able to receive the event.ACTION_UP event.