Search code examples
androidgestureimplements

How to import simple ongesture listener and override its methods properly?


I have this error: ii

It says "i dont know where to find onFling, onScroll etc from superclass of simple on gesture listener, even though i override it

my code:

package nis.tryout_erjan;

import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;

public class AnswerView  implements SimpleOnGestureListener {

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        return true ;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        super.onLongPress(e);
    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    return super.onScroll(e1, e2, distanceX, distanceY);
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        return super.onFling(e1, e2, velocityX, velocityY);
    }

    @Override
    public void onShowPress(MotionEvent e) {
        super.onShowPress(e);
    }

    @Override
    public boolean onDown(MotionEvent e) {
        return super.onDown(e);
    }

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        return super.onDoubleTap(e);
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent e) {
        return super.onDoubleTapEvent(e);
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        return super.onSingleTapConfirmed(e);
    }
}

Solution

  • SimpleOnGestureListener is not an interface but a regular class. You cannot implement it, your class has to extend it.

    public class AnswerView extends SimpleOnGestureListener