Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should simply extend <code>GestureDetector.SimpleOnGestureListener</code> in some inner class of your view and override methods you want(double tap, long press etc.) and you can handle these gestures with gesture detector containing this listener.</p> <p>Example view could look like this:</p> <pre><code>public class GestureView extends View { private GestureDetector mGestureDetector; //only one constructor for shorter code, in final code all should be presented public GestureView(Context context, AttributeSet attrs) { super(context, attrs); final MyGestureListener myGestureListener = new MyGestureListener(); mGestureDetector = new GestureDetector(context, myGestureListener); mGestureDetector.setOnDoubleTapListener(myGestureListener); } @Override public boolean onTouchEvent(MotionEvent event) { return mGestureDetector.onTouchEvent(event) || super.onTouchEvent(event); } private class MyGestureListener extends GestureDetector.SimpleOnGestureListener { @Override public boolean onDown(MotionEvent event) { return true; } @Override public void onLongPress(MotionEvent e) { //your code here } @Override public boolean onDoubleTap(MotionEvent e) { //your code here return true if event handled return super.onDoubleTap(e); } //this can be taken as click @Override public boolean onSingleTapConfirmed(MotionEvent e) { //your code here return true if event handled return super.onSingleTapConfirmed(e); } } } </code></pre> <p>If you want just to add gesture detector to some other view, you can simply call its onTouch method from onTouchListener like</p> <pre><code>view.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return gestureDetector.onTouchEvent(event); } }); </code></pre>
    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.
 

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