Note that there are some explanatory texts on larger screens.

plurals
  1. POcustom listitem click does not trigger listview.onclicklistener
    text
    copied!<p>My first question here. Please go easy on me. </p> <p>I have a <code>ListView</code> with a <code>onItemClickListener</code> implemented. </p> <p>I also have an android custom listItem consisting in a <code>RelativeLayout</code> with 2 overlapping children (LinearLayout).</p> <p>When I click on the ListItem it does NOT trigger the <code>ListView.onClickListrener</code> code. This happens only if the custom listItem has 2 overlapping children. If it has only one, everything goes well. </p> <p>Why does that happen? Thanks a lot in advance, it is driving me crazy. </p> <p><strong>custom_list_item.xml:</strong> </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="100dp" &gt; &lt;LinearLayout android:id="@+id/layout_one" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; ... &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/layout_two" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;Button ...&gt; &lt;/LinearLayout&gt; &lt;/RelativeLayout&gt; </code></pre> <p><strong>In MainActivity.java:</strong></p> <pre><code>mMainListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { ...//code reachable only when customListItem has only one child }); </code></pre> <p><strong>I've found my problem</strong></p> <p>The problem was that in the custom listItem View I added a Button - which took the focus from the listItem. </p> <p>Sorry for the ambiguous question. </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