title: Trying to catch a click on android ListView item: android:descendantFocusability="blocksDescendants" not working
body: <p>This has been addressed in many posts on StackOverflow.  The most recommended solution is to set:</p>
  
  <pre><code>android:descendantFocusability="blocksDescendants"
  </code></pre>
  
  <p>on the root layout of the list item layout.  I've done the following.</p>
  
  <ul>
  <li>Set <code>android:descendantFocusability="blocksDescendants"</code> on the root
  list item layout.</li>
  <li>Called <code>setDescendantFocusability(BLOCK)</code> on the listView, as well as
  each listViewItem.</li>
  <li>Set <code>focus=disabled</code> on the ImageButtons</li>
  </ul>
  
  <p>However when one of the child ImageButtons is clicked, I can't get any listeners on the <code>ListView</code> or <code>ListView</code> Items to fire.</p>
  
  <p>Below is the "template" I am using to render a list item.</p>
  
  <pre><code>&lt;LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/reminderItem"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:descendantFocusability="blocksDescendants"
          android:padding="0dp"&gt;
  
      &lt;RelativeLayout
              android:id="@+id/topPartOfReminder"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:padding="10dp"&gt;
  
          &lt;LinearLayout
                  android:layout_alignParentLeft="true"
                  android:layout_alignParentTop="true"
                  android:orientation="vertical"
                  android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:id="@+id/textLayout"&gt;
  
              &lt;LinearLayout
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:orientation="horizontal"&gt;
                  &lt;TextView
                          android:fontFamily="sans-serif-light"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:textSize="22sp"
                          android:text="10:00"
                          android:textStyle="normal"
                          android:id="@+id/textTime"/&gt;
                  &lt;TextView
                          android:fontFamily="sans-serif-condensed"
                          android:textSize="9sp"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:text="AM"
                          android:paddingLeft="2dp"
                          android:textStyle="normal"
                          android:id="@+id/textAmPm"/&gt;
                  &lt;TextView
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          android:text=" - "
                          android:id="@+id/textDivider"/&gt;
                  &lt;TextView
                          android:fontFamily="sans-serif-light"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:textSize="16sp"
                          android:text="March 26"
                          android:id="@+id/textDate"/&gt;
              &lt;/LinearLayout&gt;
              &lt;TextView
                      android:fontFamily="sans-serif-light"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:textSize="12sp"
                      android:text="Blah blah blah blah"
                      android:id="@+id/textDescription"/&gt;
          &lt;/LinearLayout&gt;
  
          &lt;LinearLayout
                  android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:layout_toRightOf="@+id/textLayout"
                  android:gravity="right"&gt;
  
              &lt;ImageButton
                      style="@style/HorizontalButton"
                      android:id="@+id/shiftButton"
                      android:layout_width="30dp"
                      android:layout_height="30dp"
                      android:background="@drawable/ic_action_forward"
                      android:layout_marginLeft="10dp"/&gt;
  
              &lt;ImageButton
                      style="@style/HorizontalButton"
                      android:id="@+id/repeatButton"
                      android:layout_width="30dp"
                      android:layout_height="30dp"
                      android:background="@drawable/ic_action_refresh"
                      android:layout_marginLeft="10dp"/&gt;
  
              &lt;ImageButton
                      style="@style/HorizontalButton"
                      android:id="@+id/tickButton"
                      android:layout_width="30dp"
                      android:layout_height="30dp"
                      android:background="@drawable/ic_action_done"
                      android:layout_marginLeft="10dp"/&gt;
  
          &lt;/LinearLayout&gt;
      &lt;/RelativeLayout&gt;
  
  
      &lt;LinearLayout
              android:id="@+id/tickButtonsView"
              android:layout_width="match_parent"
              android:layout_height="50dp"
              android:padding="0dp"
              android:orientation="horizontal"
              android:visibility="gone"&gt;
  
          &lt;Button style="@style/HorizontalButton" android:text="OK"/&gt;
          &lt;View style="@style/VerticalDivider"/&gt;
          &lt;Button style="@style/HorizontalButton" android:text="Cancel"/&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
              android:id="@+id/repeatButtonsView"
              android:layout_width="match_parent"
              android:layout_height="50dp"
              android:padding="0dp"
              android:orientation="horizontal"
              android:visibility="gone"&gt;
  
          &lt;Button style="@style/HorizontalButton" android:text="day"/&gt;
          &lt;View style="@style/VerticalDivider"/&gt;
          &lt;Button style="@style/HorizontalButton" android:text="weekday"/&gt;
          &lt;View style="@style/VerticalDivider"/&gt;
          &lt;Button style="@style/HorizontalButton" android:text="week"/&gt;
          &lt;View style="@style/VerticalDivider"/&gt;
          &lt;Button style="@style/HorizontalButton" android:text="month"/&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
              android:id="@+id/shiftButtonsView"
              android:layout_width="match_parent"
              android:layout_height="50dp"
              android:padding="0dp"
              android:orientation="horizontal"
              android:visibility="gone"&gt;
  
          &lt;Button style="@style/HorizontalButton" android:text="1 week"/&gt;
          &lt;View style="@style/VerticalDivider"/&gt;
          &lt;Button style="@style/HorizontalButton" android:text="1 day"/&gt;
          &lt;View style="@style/VerticalDivider"/&gt;
          &lt;Button style="@style/HorizontalButton" android:text="1 hour"/&gt;
          &lt;View style="@style/VerticalDivider"/&gt;
          &lt;Button style="@style/HorizontalButton" android:text="10 mins"/&gt;
  
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Am also setting this descendantFocusability in the code, just to be sure:</p>
  
  <pre><code>public class ReminderItemAdapter extends CursorAdapter {
      . . .
  
      @Override
      public View newView(Context context, Cursor cursor, ViewGroup parent) {
          View v = mLayoutInflater.inflate(R.layout.reminder_item, parent, false);
          parent.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
          ((ViewGroup) v).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
          return v;
      }
  </code></pre>
  
  <p>And on the styling of my ImageButton's I've set focusable=false, just for good measure:</p>
  
  <pre><code>&lt;resources&gt;
      &lt;style name="HorizontalButton"&gt;
          &lt;item name="android:layout_width"&gt;0dip&lt;/item&gt;
          &lt;item name="android:layout_weight"&gt;1&lt;/item&gt;
          &lt;item name="android:layout_height"&gt;match_parent&lt;/item&gt;
          &lt;item name="android:fontFamily"&gt;sans-serif&lt;/item&gt;
          &lt;item name="android:textSize"&gt;12sp&lt;/item&gt;
          &lt;item name="android:background"&gt;?android:attr/selectableItemBackground&lt;/item&gt;
          &lt;item name="android:focusable"&gt;false&lt;/item&gt;
          &lt;item name="android:focusableInTouchMode"&gt;false&lt;/item&gt;
      &lt;/style&gt;
      . . .
  </code></pre>
  
  <p>I am getting onClick's received when clicking on any part of the list item, including the child TextView elements.  However when clicking on any of the ImageButtons, the click's don't get picked up.  (BTW I have got OnClickListeners registered with the ImageButtons and they are getting called.)</p>
  
  <p>Have set:</p>
  
  <ul>
  <li>setOnItemClickListener on ListView </li>
  <li>setOnItemSelectedListener on ListView </li>
  <li>setOnClickListener on each ListView Item.</li>
  </ul>
  
  <p>But none of these get called if one of the ImageButtons is clicked.</p>
  
  <p>Any help would be appreciated.</p>