我想突出顯示點擊自定義列表視圖的項目。我嘗試了不同的選擇,但不是他們正在工作。有人能告訴我什麼是錯的嗎?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