In my app I have inflated a ListView with this row:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:gravity="center"
android:orientation="horizontal" android:layout_height="wrap_content"
android:id="@+id/rootrow_layout" android:clickable="true"
android:focusable="true" android:focusableInTouchMode="true">
<LinearLayout android:layout_height="fill_parent"
android:id="@+id/containerHistory" android:layout_width="fill_parent"
android:layout_weight="1">
<LinearLayout android:layout_weight="1"
android:orientation="vertical" android:layout_gravity="center"
开发者_开发知识库 android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_marginLeft="2dip">
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<TextView android:textSize="16sp" android:gravity="left"
android:padding="5dp" android:layout_width="fill_parent"
android:text="Unknown location " android:id="@+id/historyLocation"
android:layout_height="wrap_content" android:textColor="#000000"></TextView>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout03"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<TextView android:layout_weight="1" android:textSize="12sp"
android:gravity="left" android:padding="5dp" android:layout_width="fill_parent"
android:text="Complete" android:typeface="serif" android:id="@+id/historyDate"
android:layout_height="wrap_content" android:textColor="#000000"></TextView>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout04"
android:layout_height="wrap_content" android:layout_width="wrap_content"></LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_marginRight="2dip" android:id="@+id/linearLayout1"
android:layout_height="match_parent" android:layout_width="wrap_content">
<CheckBox android:id="@+id/check" android:layout_gravity="center"
android:layout_height="fill_parent" android:layout_width="wrap_content"></CheckBox>
</LinearLayout>
</LinearLayout>
Now I would add an event (OnClickListener) on my root layout. I can get the event but I can't see the default selector (for example I have Galaxy S2 and on list click I have a blue background).
Can I set the default selector on LinearLayout click event?
I attach a screenshot for my default selector on Galaxy S2.
Sorry, I've tried solution:
@android:drawable/list_selector_background
Modify your root LinearLayout to become like this (NOTICE THE LAST LINE!)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:gravity="center"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:id="@+id/rootrow_layout"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="@android:drawable/list_selector_background">
add this code in your xml list view.
android:listSelector="@android:drawable/list_selector_background"
精彩评论