Android listview - list item with 1 button works ok, adding an imagebutton is not ok

In a listview I used a row with 1 button. This works fine. I can click on the button and handle it. Furthermore, I can click on the list item and the event is generated. Even a longpress on the list works fine.

When adding an imagebutton, then no list item click or list longpress event is triggered. Why?

First you will see the list-row that works fine (with 1 button).

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="35dp"
    android:padding="5dp"
    android:background="@drawable/list_selector"
    android:orientation="horizontal" >

<Button
    android:id="@+id/answer_usable"
    android:layout_width="40dp"
    android:layout_weight="0"
    style="@style/btnStyleGeocaching"
    android:textSize="12sp"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:layout_marginRight="5dp"
    android:text="Set" />

<LinearLayout 
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/variable"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:singleLine="true"
        android:layout_weight="1"
        android:text=""
        android:textSize="20sp"
        android:textStyle="bold" >

    </TextView>
    <TextView
        android:id="@+id/answer"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text=""
        android:textSize="20sp"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_alignParentRight="true"
        android:singleLine="true"
        android:textStyle="bold" >
    </TextView>
</LinearLayout>

    <TextView
        android:id="@+id/formula"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:text=""
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:textSize="13sp" >
    </TextView>
</LinearLayout>

<!-- second button comes here -->

</LinearLayout>

When adding a second imagebutton at the place just above the last linear layout, then no click on the list or longpress is triggered. Only the buttons receive button clicks.

<ImageButton
    android:id="@+id/variable_edit"
    android:layout_width="40dp"
    android:layout_weight="0"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_action_edit"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:layout_marginLeft="5dp" />

The listview is:

<ListView
    android:id="@+id/fragment_vars_list"
    android:layout_height="0dip"
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:divider="#00000000"
    android:dividerHeight="6dp"
    android:choiceMode="singleChoice"
    android:scrollbars="vertical" />

It does not matter to add focusable=true to the listview.

Answers


Solved it ... when using an ImageButton ... I cannot click on the list item. Changing the ImageButton by a Button, then everything works as expected.

Then you can click on both buttons AND click (or longpress) on a listrow.

Anyone a clue?

Well, it works.


Need Your Help

Find closest lat/lng in PHP for an array of input values

php arrays maps

I have code that, for an array of lat/long pairs, finds the nearest lat/long pair from another array:

Indenting for code-generation

php code-generation metaprogramming

Often, programmers write code that generates other code.