Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble implementing OnGestureListere on a custom view
    primarykey
    data
    text
    <p>I want to implement a listener for my view. I want to detect a simple click a double tap and a long press and that is all. Here is the code I wrote (pertinent parts only):</p> <pre><code>public class BoardView extends View implements OnGestureListener, OnDoubleTapListener{ //My functions and code. @Override public boolean onTouchEvent(MotionEvent event){ Toast t = Toast.makeText(this.getContext(), "I'm touched", Toast.LENGTH_SHORT); t.show(); System.err.println("On Touch"); return super.onTouchEvent(event); } public void onLongPress(MotionEvent event) { Toast t = Toast.makeText(this.getContext(), "I get it, stop touching me!!!", Toast.LENGTH_SHORT); t.show(); System.err.println("Long Press"); //Log.d(DEBUG_TAG, "onLongPress: " + event.toString()); } @Override public void onGesture(GestureOverlayView overlay, MotionEvent event) { } @Override public void onGestureCancelled(GestureOverlayView overlay, MotionEvent event) { } @Override public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) { } @Override public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) { // TODO Auto-generated method stub } @Override public boolean onDoubleTapEvent(MotionEvent e) { return false; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { // TODO Auto-generated method stub return false; } @Override public boolean onDoubleTap(MotionEvent e) { Toast t = Toast.makeText(this.getContext(), "Soy double the joy", Toast.LENGTH_SHORT); t.show(); System.err.println("Double Tap"); return true; } } </code></pre> <p>I detect the touch perfectly but not the double tap or the long press.... what am I doing wrong?</p> <p>EDIT: Following one of the answers I wrote the following code:</p> <pre><code>private class Gestures extends SimpleOnGestureListener{ public Gestures(){ } public void onTouchEvent(MotionEvent event){ System.err.println("Touch Even gestures"); } @Override public void onLongPress(MotionEvent event) { System.err.println("Long Press"); } @Override public boolean onDoubleTap(MotionEvent event) { System.err.println("Double Tap"); return true; } } Gestures gdetector = new Gestures(); </code></pre> <p>This is before my BoardView constructor. Then as I understand I should have done:</p> <pre><code>@Override public boolean onTouchEvent(MotionEvent event){ gdetector.onTouchEvent(event); return super.onTouchEvent(event); } </code></pre> <p>However I only got the simple touch detected....</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload