10

I'm trying to get my list items in a ListView clickable. At the moment they are clickable (see my screenshot) but they're only clickable within the rectangle the text takes up.

I'm using protected void onListItemClick(ListView l, View v, int position, long id) { for the clickable list items.

Here is my list.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
    android:layout_height="wrap_content">
<ListView android:id="@+id/android:list"
      android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
<TextView android:id="@+id/android:empty"
      android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_favorites"/>

and my row.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical" >
    <TextView android:id="@+id/artist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    <TextView android:id="@+id/songtitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_alignParentRight="true"/>
    <TextView android:id="@+id/album"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_alignParentRight="true"/>
    <TextView android:id="@+id/playtime"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_alignParentRight="true"/>
    <TextView android:id="@+id/playlistnum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_alignParentRight="true"
        android:visibility="gone" />
</LinearLayout>

And here's the screenshot example: (New users aren't allowed to post images... grumble... have a hyperlink!)

In list.xml, the Listview has android:layout_width="fill_parent" so it should be the full width of the screen. (All of the items in row.xml are also width="fill_parent".) What am I missing?

Jeromy French
  • 11,812
  • 19
  • 76
  • 129
Civilian
  • 614
  • 2
  • 9
  • 29

1 Answers1

11

The TextView in your list.xml needs to be set to fill_parent. The selection will then fit the width of the parent ListView.

      android:layout_width="wrap_content"
JLB
  • 242
  • 3
  • 8
  • Tried it, didn't work. That TextView is only used when the list is empty. :/ – Civilian Jun 27 '11 at 18:31
  • 3
    hmmm.... Ah, only other difference in my code and yours would be the LinearLayout also set to fill_parent on the layout_width. Give that a try. If that doesn't work I'll open my code up and post it here. – JLB Jun 27 '11 at 18:47
  • 3
    To be clear I was referring to the LinearLayout in your list.xml in my last comment. It's set to wrap_content. Worked for me changing that to fill_parent. – JLB Jun 27 '11 at 19:02