1

I need to implement logic for panning surface and be able to click on it to place image, but when I'm trying to add gesture detector as simple as:

public boolean onTouchEvent(MotionEvent event) {
    if (gestureDetector.onTouchEvent(event)) {
        return true;
    } else {
        return super.onTouchEvent(event);
    }
}

And when I'm starting gesture, image being placed on screen. Please help.

acm0x
  • 775
  • 6
  • 14

3 Answers3

3

Check here:

Fling gesture detection on grid layout

Community
  • 1
  • 1
Kamen
  • 3,575
  • 23
  • 35
  • Yes, thankyou, it help. I just missed that thing that click event is followed by gesture if I'm returning false as a gesture result. – acm0x May 26 '11 at 16:30
  • Interesting thing, that setOnClickListener() is required even if there's no logic in it (I've moved all logic to onSingleTapUp() – acm0x May 26 '11 at 16:40
1

As Hyperboreus said, use the GestureDetector.OnGestureListener interface which you associate to your GestureDetector instance. No need then to associate a click listener to your view and a touch listener. Specifically, use the GestureDetector.OnGestureListener.onSingleTapUp(MotionEvent) method for detecting clicks, the GestureDetector.OnGestureListener.onFling(MotionEvent, MotionEvent, float, float) method for detecting flings, and so on and so forth.

Remember to return true in your implementation of the GestureDetector.OnGestureListener.onDown(MotionEvent) method.

Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
1

Use the classes and interfaces from android.gesture, especially OnGestureListener. The OS takes of care of recognizing gestures.

Hyperboreus
  • 31,997
  • 9
  • 47
  • 87