我想突出显示单击自定义列表视图的项目。我尝试了不同的选项,但没有一个有效。有人可以告诉我有什么问题吗?
我的自定义列表视图com.foo.ViewEditListView extends ListView implements android.widget.AdapterView.OnItemLongClickListener
list_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView_list_info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
>
</TextView>
<EditText
android:id="@+id/searchQueryText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:drawableRight="@drawable/search"
android:hint="Search Expenses by Amount"
android:textColorHint="#5e8e19"
android:inputType="numberSigned|numberDecimal"
style="@android:style/TextAppearance.Small"
>
</EditText>
<com.foo.ViewEditListView
android:id="@+id/viewExpenseListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@/drawable/list_selector_bg" //doesn't work
/>
</LinearLayout>
list_row.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@/drawable/list_selector_bg" //doesn't work
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/v_row_field1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#C11B17"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="@+id/v_row_field2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textStyle="bold"
android:layout_marginRight="2dp" />
</RelativeLayout>
</LinearLayout>
list_selector_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true"
android:drawable="@android:drawable/list_selector_background" />
</selector>
我也尝试在 Activity 中设置选择器,但它们都没有工作。现在,我一无所知。有人可以在这里帮助我吗?
如果我将 android:background="@/drawable/list_selector_bg" 放入 RelativeLayout,它只会突出显示该部分。但我希望突出显示整个布局。
谢谢CP