Ontouchlistener Not Working Inside Activity
so I had some problems with the onTouch method, it didnt do anything, at first i thought something wrogn with the code but then i did this, and it still doesnt work when i touch th
Solution 1:
You need to override the
publicbooleanonTouchEvent(MotionEvent e)
method of the Activity
class, not the method you are overriding (onTouch(...)
of the OnTouchListener
). Then it should work. Example:
@OverridepublicbooleanonTouchEvent(MotionEvent e) {
// do your stuff...returnfalse;
}
This means you are recognizing touch events on the Activity
, not on the View
. If you want to explicitly detect touches on the View
via OnTouchListener
, you need to set the OnTouchListener
for your View
.
In your case:
fpv = new FartPianoView(this);
fpv.setOnTouchListener(this);
Post a Comment for "Ontouchlistener Not Working Inside Activity"