0

When I use a ImageButton in the ListView row, the ros is no selectable. When I change it to a ImageView it is selectable.

I have this simple row layout, and below is my list , am I missing something simple?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
android:orientation="horizontal"
android:id="@+id/layoutrowtop">

    <ImageButton android:id="@+id/imgDetailDisclosure" 
    android:layout_height="fill_parent" 
    android:layout_width="48dip" 
    android:layout_gravity="center_vertical"
    android:background="#00000000">
    </ImageButton>

    <RelativeLayout 
        android:layout_width="wrap_content"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:padding="6dip">

                <TextView android:id="@+id/firstLine" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:ellipsize="marquee"
                android:textStyle="bold"
                android:textSize="18dp"
                android:singleLine="true"
                android:gravity="top"
                ></TextView>

                <TextView android:id="@+id/secondLine" 
                android:layout_height="fill_parent" 
                android:layout_below="@+id/firstLine" 
                android:layout_width="wrap_content"
                android:ellipsize="marquee"
                android:textStyle="italic"
                android:textSize="14dp"
                android:singleLine="false"
                android:gravity="top"
                android:lines="2"></TextView>
    </RelativeLayout>
</LinearLayout>

<LinearLayout  
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_width="fill_parent">
<EditText  
    android:id="@+id/search_box"
    android:layout_height="wrap_content" 
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:hint="type to filter"
    android:inputType="text"/>

<ImageButton 
    android:id="@+id/search_button"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:src="@drawable/icon_mag_glass"/>

</LinearLayout>

<!-- Set height to 0, and let the weight param expand it -->
<!-- Note the use of the default ID! This lets us use a ListActivity still! -->
<ListView android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1" />

Ian Vink
  • 66,960
  • 104
  • 341
  • 555

1 Answers1

1

You added an object that is focusable (the ImageButton) to your ListView, which makes the ListView items not focusable. See related question for some more details and options: TextView and Button in each row and onListItemClick()

Community
  • 1
  • 1
Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82