Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to support native ListView item click while having scrollable ListItem
    primarykey
    data
    text
    <h2>Problem</h2> <p>While developing some kind of "Contextual actions" for ListView item on swipe gesture I have been a little bit confused about the way Android dispatches MotionEvents to ViewGroup's children.</p> <p>According to documentation all the things start with <code>ViewGroupd.dispatchTouchEvent(MotionEvent)</code> method call. Then view group ask whether the particular motion event should be intercepted or we can dispatch it to our childrens. This works great with all kinds of scrolling so we can efficiently resolve conflicts between vertical and horizontal scrolling (for example ListView inside ViewPager).</p> <p>However I can't successfully handle simple click event in list view this way. Motion events dispatching trace looks like this</p> <ol> <li><code>ListView.dispatchTouchEvent(DOWN)</code></li> <li><code>ListView.onInterceptTouchEvent(DOWN)</code> <strong>returns <code>false</code></strong>;</li> <li><code>QuickActionView.dispatchTouchEvent(DOWN)</code></li> <li><code>QuickActionView.onTouchEvent(DOWN)</code> <strong>return <code>true</code></strong> because MotionEvent.ACTION_DOWN indicates about start of gesture and it possibly can be horizontal scroll and we should appear quick actions layout to the user in this case. If we return <code>false</code> from here on <code>MotionEvent.ACTION_DOWN</code> it prevents from other touch events to be dispatched to this child of ListView.</li> <li>Due to step 4 <code>QuickActionView.dispatchTouchEvent(DOWN)</code> <strong>return <code>true</code></strong></li> <li>Due to step 5 <code>ListView.dispatchTouchEvent(DOWN)</code> <strong>return <code>true</code></strong></li> </ol> <p>As a result ListView remember touch target. So next message dispatched like this.</p> <ol> <li><code>ListView.dispatchTouchEvent(UP)</code></li> <li><code>ListView.onInterceptTouchEvent(UP)</code> <strong>returns <code>false</code></strong>;</li> <li><code>QuickActionView.dispatchTouchEvent(UP)</code></li> <li><code>QuickActionView.onTouchEvent(UP)</code> <strong>return <code>false</code></strong> because we now see that the gesture is over and it isn't scroll or fling or whatever.</li> <li>Due to step 4 <code>QuickActionView.dispatchTouchEvent(UP)</code> <strong>return <code>false</code></strong></li> <li>Due to step 5 <code>ListView.dispatchTouchEvent(UP)</code> <strong>return <code>false</code></strong></li> </ol> <p>So there is no chance for ListView to handle item click because after step 5 with UP action the motion event doesn't directed to the ListView's <code>onTouchEvent(MotionEvent)</code> method.</p> <p>I have also tried to "intercept" touch event with ACTION_UP inside ListView, but have noticed that according to Android documentation after interception only further motion events will be directed to the ViewGroup's <code>onTouchEvent(MotionEvent)</code> method, and the current one won't.</p> <h2>Question</h2> <p>How can I support both the ListView's native item click handling and ability to dispatch MotionEvents to ListItem view (it is horizontal scrollable and have image buttons)?</p> <p>It is preferred to hear from someone experienced in such a problem solving or have deeper understanding about how it designed to work with specified conflict solving</p>
    singulars
    1. This table or related slice is empty.
    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. 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