0

I have built a home screen widget that uses a list view and list items with a relative layout that contains two text views and an image view. What I want is that when you click on an item in the list view the full item should be selected and not as now only the text view or image view that you happen to click on. How can I do this? I have tried some stuff but nothing worked. Bellow is an image that shows how it looks now.

Only row two is selected

Here is the widget layout,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="0dp"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#80FFFFFF"
    android:orientation="horizontal" >

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:contentDescription="@string/widget_icon_description"
        android:src="@drawable/ic_logo" />

    <TextView
        android:id="@android:id/text1"
        style="@android:style/TextAppearance.DeviceDefault.Large.Inverse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:gravity="center_vertical"
        android:text="@string/widget_list_heading"
        android:textIsSelectable="false" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_blue_bright"
    android:paddingBottom="2dp" >
</LinearLayout>

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_marginBottom="0dp"
    android:layout_weight="1"
    android:background="#f1f1f1"
    android:listSelector="@android:color/holo_blue_bright"
    android:paddingBottom="0dp" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_blue_bright"
    android:paddingBottom="2dp" >
</LinearLayout>

And here is the list view item layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:background="@drawable/list_selector_background_light" >

<TextView
    android:id="@android:id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMediumInverse"
    android:textIsSelectable="false"
    android:textStyle="bold" />

<TextView
    android:id="@android:id/text2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@android:id/text1"
    android:layout_below="@android:id/text1"
    android:textAppearance="?android:attr/textAppearanceSmallInverse"
    android:textIsSelectable="false" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:paddingRight="10dip"
    android:paddingTop="8dip" >

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/expandable_heading_list_item_image_description" />
</LinearLayout>

/Viktor

Viktor
  • 476
  • 3
  • 16
  • For API Level 11+, you can use a `ListView`. – CommonsWare Aug 05 '13 at 18:23
  • I use a list view with a custom list view item. Works great if I only use android.R.layout.simple_list_item_1 or android.R.layout.simple_list_item_2 but I need more advanced layout. – Viktor Aug 05 '13 at 18:27

1 Answers1

0

Ok, found the solution now, 13 minutes after asking the question... Just added "android:clickable=true" to the relative layout in the list view item and added "android:clickable=false" to the sub items of the layout, removed all pending intents from the text views and image view and added it to the relative layout. The intent is not working but that's hopefully something that can be solved.

/Viktor

Viktor
  • 476
  • 3
  • 16