Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Expanding on Mirek's answer, for the case when you want to use the swipe gestures inside a scroll view. By default the touch listener for the scroll view get disabled and therefore scroll action does not happen. In order to fix this you need to override the <code>dispatchTouchEvent</code> method of the <code>Activity</code> and return the inherited version of this method after you're done with your own listener.</p> <p>In order to do a few modifications to Mirek's code: I add a getter for the <code>gestureDetector</code> in the <code>OnSwipeTouchListener</code>.</p> <pre><code>public GestureDetector getGestureDetector(){ return gestureDetector; } </code></pre> <p>Declare the <code>OnSwipeTouchListener</code> inside the Activity as a class-wide field.</p> <pre><code>OnSwipeTouchListener onSwipeTouchListener; </code></pre> <p>Modify the usage code accordingly:</p> <pre><code>onSwipeTouchListener = new OnSwipeTouchListener(MyActivity.this) { public void onSwipeTop() { Toast.makeText(MyActivity.this, "top", Toast.LENGTH_SHORT).show(); } public void onSwipeRight() { Toast.makeText(MyActivity.this, "right", Toast.LENGTH_SHORT).show(); } public void onSwipeLeft() { Toast.makeText(MyActivity.this, "left", Toast.LENGTH_SHORT).show(); } public void onSwipeBottom() { Toast.makeText(MyActivity.this, "bottom", Toast.LENGTH_SHORT).show(); } }); imageView.setOnTouchListener(onSwipeTouchListener); </code></pre> <p>And override the <code>dispatchTouchEvent</code> method inside <code>Activity</code>:</p> <pre><code>@Override public boolean dispatchTouchEvent(MotionEvent ev){ swipeListener.getGestureDetector().onTouchEvent(ev); return super.dispatchTouchEvent(ev); } </code></pre> <p>Now both scroll and swipe actions should work.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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