Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is common question for <code>ListView</code>. I read source code about this. <br/>Question: why <code>onListItemClick</code> not be called? <br/>Answer:</p> <ul> <li><code>AbsListView</code> class override <a href="https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/AbsListView.java#L3599" rel="nofollow">onTouchEvent</a> method.</li> <li>Snip code come from <a href="https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/AbsListView.java#L3599" rel="nofollow">onTouchEvent</a> method. <pre> <code> if (inList &amp;&amp; !child.hasFocusable()) { if (mPerformClick == null) { mPerformClick = new PerformClick(); } ..... } </code></pre> <br/>PerformClick will be call if child.<a href="https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewGroup.java#L873" rel="nofollow">hasFocusable</a>() return false which child is you ListView item view;</li> <li>Snip code come from <code>hasFocusable</code> method.</li> </ul> <pre> <code> @Override public boolean hasFocusable() { if ((mViewFlags & VISIBILITY_MASK) != VISIBLE) {return false; } if (isFocusable()) {return true;} final int descendantFocusability = getDescendantFocusability(); if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) { final int count = mChildrenCount; final View[] children = mChildren; for (int i = 0; i </pre> <p><br/> So solution:<br/> Solution A,set ListView item descendantFocusability property, let its <code>getDescendantFocusability</code>() is not equal <code>FOCUS_BLOCK_DESCENDANTS</code>.<br/> Solution B, ListView item all child views is not hasFocusable( hasFocusable()</code> return false).</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