Reputation: 731
I am adding a touch listener to a view.
here is the code:
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return super.onTouch(v, event);
}
});
But I keep getting the error:
The method onTouch(View, MotionEvent) is undefined for the type Object.
Why do I keep getting this error. Is there something I need to add to my app to make it work?
Upvotes: 0
Views: 3261
Reputation: 5407
You must not call super in the onTouch
-Method: Instead return false or true like you need it.
(JavaDoc: True if the listener has consumed the event, false otherwise.)
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
Upvotes: 6
Reputation: 5685
You're getting it because you're actually implementing an interface called View.OnTouchListener rather than extending the View
Upvotes: 1