Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Width of clickable area in ListView w/ onListItemClick

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?

like image 854
Civilian Avatar asked Jun 27 '11 18:06

Civilian


People also ask

How to get data from ListView by Clicking item on ListView?

Try this: my_listview. setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } });


1 Answers

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"
like image 80
JLB Avatar answered Oct 04 '22 00:10

JLB