-1

I have this layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="blocksDescendants">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/textViewId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"/>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/textViewText"
                android:layout_marginTop="5dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:singleLine="false"
                android:layout_weight="1" />


            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/buttonOk"
                android:clickable="true"
                android:focusable="false"/>
        </LinearLayout>

    </LinearLayout>
</RelativeLayout>

The layout is used in a ListFragment. I also have the following code:

@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
    MyItem item = items.get(position);

    //Do something...
}

I have a custom adapter and a viewholder. But the listview items are not clickable. Currently I still didn't any code for the button itself. I want to be able to click on the whole listview item too.

Isn't the above the correct way to do it?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263

1 Answers1

1

In your ListView , use the setOnItemClickListener.

This is the simplest way of handling click events on ListView

Prabhuraj
  • 928
  • 2
  • 8
  • 14