Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onTouchListener class in SurfaceView

I am trying to implement a onTouchListener so i can call it from a different class...

public OnTouchListener nextListener = new OnTouchListener() {
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
        //stuff

        }

        return true;

    }

};

And it keeps throwing me this error. "Class anonymous class derived from onTouchListener must either be abstract or implement abstract method". I know it is something small because I had it working earlier.

like image 413
ctapp1 Avatar asked Aug 08 '26 14:08

ctapp1


1 Answers

The default method is called onTouch not onTouchEvent

public View.OnTouchListener nextListener = new View.OnTouchListener() {


    public boolean onTouch(View v, MotionEvent event) {
       if (event.getAction() == MotionEvent.ACTION_DOWN) {
            //stuff

        }

        return true;
    }
};

From the android api

From the android api

like image 138
Eric Lamas Avatar answered Aug 11 '26 03:08

Eric Lamas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!