使用GestureDetector进行LongPress检测不起作用

时间:2013-12-11 17:57:02

标签: android gestures

我想在我的Android应用程序中捕获一个LongPress-Gesture,但是this.gestureDetector.onTouchEvent(event)总是返回false。我在LogCat中得到了“Longpress detect”,但是onTouchEvent总是返回false - 这里有什么想法吗?

final GestureDetector gestureDetector = new GestureDetector(this.getContext(),
            new GestureDetector.SimpleOnGestureListener() {
                @Override
                public void onLongPress(MotionEvent event) {
                    Log.e(TAG, "Longpress detected");
               }
            });

@Override
public boolean onTouchEvent(MotionEvent event) {

    boolean test = this.gestureDetector.onTouchEvent(event);
    Log.v(TAG, Boolean.toString(test)); // test is _always_ false
    if (test) {
       // Do something
        return test;
    }
    return super.onTouchEvent(event);
}

1 个答案:

答案 0 :(得分:0)

因为onLongPress没有返回值,所以它被定义为void。

 public void onLongPress(MotionEvent event) {
                     Log.e(TAG, "Longpress detected");
                }