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?
Try this: my_listview. setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } });
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With