How to detect 5 second lasting touch event on Activity?
I would like to detect when user touches screen constantly for 5 se开发者_运维知识库conds. No things like onLongTouch() are taken into consideration. Mechanism should be transparent, because I'm overriding onTouchEvent() to change Views in ViewFlipper.
Should I do it manually by creating new thread that would be timing a touch?
You can start a timer when the MotionEvent is MotionEvent.ACTION_DOWN and stop it when the event is MotionEvent.ACTION_UP. This is the time the user had his finger on the screen (including dragging). If you want to restart the timer on dragging, check for ACTION_MOVE and restart the timer. But I don't recommend doing that since these events might be thrown even if the user accedintly moved his hand very slightly while holding his finger down on the screen.
精彩评论