Java – How do I make ListView touch-sensitive to clicking an item?

How do I make ListView touch-sensitive to clicking an item?… here is a solution to the problem.

How do I make ListView touch-sensitive to clicking an item?

I have a ListView in a ListActivity filled with strings. However, only the text portion of the list item is clickable, and when it is clicked, only the text part is highlighted (orange on a black background). I want to make the entire row clickable, and when selected, the entire row should be marked as selected.

What should I do? Here is my layout XML:

<?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="fill_parent"
    android:orientation="vertical" >

<TextView
        android:id="@+id/TextViewLocationMode"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="-" >
    </TextView>

<TextView
        android:id="@+id/TextViewStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Statustekst" >
    </TextView>

<ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:choiceMode="singleChoice"
        android:clickable="true"
        android:fadeScrollbars="true"
        android:isScrollContainer="true"
        android:longClickable="true" >
    </ListView>

</LinearLayout>

Solution

This is the default behavior – are you sure your ListView and custom row layout (if you’re using) set to width=”fill_parent”? If they are already on width=”fill_parent”, please post your XML and/or code so we can see what the problem is.

Related Problems and Solutions