Michal Chudy
Michal Chudy

Reputation: 1893

How to detect 5 second lasting touch event on Activity?

I would like to detect when user touches screen constantly for 5 seconds. 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?

Upvotes: 0

Views: 300

Answers (1)

IncrediApp
IncrediApp

Reputation: 10353

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.

Upvotes: 3

Related Questions