Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I hate to answer my own question but I finally figured this one out. Basically, you must intercept the touch events that the Activity is sent. In the intercept function you can then determine what touch events you want to handle and what events you want to let pass through to the Activity and other child items.</p> <p>Here is what I had that enabled me to capture "swipe" or "fling" events while letting all other touch events through (e.g. it lets scroll up and down, long press, button press events through).</p> <pre><code> MotionEvent _downMotionEvent; /** * This function intercepts all the touch events. * In here we decide what to pass on to child items and what to handle ourselves. * * @param motionEvent - The touch event that occured. */ @Override public boolean dispatchTouchEvent(MotionEvent motionEvent){ if (_debug) Log.v("NotificationActivity.dispatchTouchEvent()"); NotificationViewFlipper notificationViewFlipper = getNotificationViewFlipper(); switch (motionEvent.getAction()){ case MotionEvent.ACTION_DOWN:{ //Keep track of the starting down-event. _downMotionEvent = MotionEvent.obtain(motionEvent); break; } case MotionEvent.ACTION_UP:{ //Consume if necessary and perform the fling / swipe action //if it has been determined to be a fling / swipe float deltaX = motionEvent.getX() - _downMotionEvent.getX(); final ViewConfiguration viewConfiguration = ViewConfiguration.get(_context); if(Math.abs(deltaX) &gt; viewConfiguration.getScaledTouchSlop()*2){ if (deltaX &lt; 0){ //Do work here for right direction swipes. return true; }else if (deltaX &gt; 0){ //Do work here for left direction swipes. return true; } } break; } } return super.dispatchTouchEvent(motionEvent); } </code></pre> <p>I hope that this helps anyone else who ran into a similar problem.</p>
 

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