0

How do I perform something while the something is long pressed and something when it is released? I am using Gesture Detector to handle events

Kai
  • 38,985
  • 14
  • 88
  • 103
dungeon_master
  • 191
  • 1
  • 1
  • 8

1 Answers1

0

The longpress is a specific action. For your purposes I think you will have to look at onTouchEvent(MotionEvent ev)

ACTION_DOWN is when a press has started.

ACTION_UP is when it is released.

Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
  • So how do I customize this onTouch for a LongPress? – dungeon_master Jun 05 '13 at 12:25
  • put the "something1" you want to execute in ACTION_DOWN, put the other "something2" you want to execute in ACTION_UP. When user presses down, "something1" will fire. When they let go, "something2" will fire. Is this not what you want? If not please describe when you want things to happen. – Ken Wolf Jun 05 '13 at 12:30
  • In this case, 'something1' will fire immediately when the user touches the screen, I want it to fire up when he has long pressed the screen and keep going on till he releases the screen. As he releases, 'something2' should immediately fire. – dungeon_master Jun 06 '13 at 04:10
  • I'd find out how long a long-press is (`ViewConfiguration.getLongPressTimeout()` will tell you), on first ACTION_DOWN set up a handler/timer to fire "something1" after that period of time (cancel it if you get ACTION_UP before then, this indicates the user has not pressed as long as a long-press). First time you get ACTION_UP after that time, fire "something2". This will do what you describe above. – Ken Wolf Jun 06 '13 at 05:03