Reputation: 506
I need to know how i can make my activity to know when a user touches the screen, double touches it, or holding the finger on it for a long touch on a single view, with out using buttons
Could some one briefly describe me witnh what i should work here, and what logic to use?
Upvotes: 0
Views: 989
Reputation: 67522
You need to have some View
or layout item that encompasses the screen, so that all the touch events are sent to it. From there, you need to attach a listener of some kind (touch or gesture, probably).
I would recommend either a GestureDetector
(this supports double tapping and other gestures), or a basic touch listener (uses MotionEvent
, which doesn't have double tap, but you could implement this yourself).
If you use MotionEvent
, you can detect how long the finger has been down with getDownTime()
. For a double tap, you can record the time of the last press (using Calendar
or similar), then check if the last press was within some amount of time (maybe 500ms?).
If you use GestureDetector
, you can implement these differently. Take a look at this answer for more details (other answers in that thread provide alternatives as well). It also supports MotionEvent
objects, so that shouldn't be a problem.
Upvotes: 1