我想突出显示点击自定义列表视图的项目。我尝试了不同的选择,但不是他们正在工作。有人能告诉我什么是错的吗?Android CustomListView高亮点击项目
我的自定义列表视图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>
我也试图在setSelector活动,但他们都不工作。现在,我无能为力。有人可以帮我吗?
如果我把android:background =“@/drawable/list_selector_bg”放到RelativeLayout中,它只会突出显示那部分。但我希望整个布局突出显示。
感谢 CP
嗨Raghunandan,我想你的解决方案。但它不起作用。还是一样的行为。你认为VieEditListView导致一些问题吗? – Chintan 2013-04-22 00:52:12
@Chintan如果你做得对,这应该起作用。我用自定义drawable作为背景的列表视图行也一样。 – Raghunandan 2013-04-22 04:21:27
谢谢拉古南丹。它正在工作! – Chintan 2013-04-22 23:59:01