2015-04-19 20 views

回答

1

不,你不應該。

當您輸入Multi Choice Mode(通常通過長按一個列表項來觸發它)主onItemClick偵聽器將被重寫,並且所有將被按下的項目將被標記爲選中。

+0

好的。謝謝。但是如何在選擇listitem時改變顏色?我問過這個問題,但沒有人給我答案。 – Arnes

+0

@Arnes你使用標準的item.xml還是自定義? – udenfox

+0

@阿內斯無論如何。最簡單的方法:將android:background =「?android:attr/activatedBackgroundIndicator」設置爲列表項xml的根元素您可以使用listView。 我認爲這個答案對你有幫助:http://stackoverflow.com/a/16976534/3809678 – udenfox

1

不會改變背景顏色。列表項的根元素是RelativeLayout(在我的情況下)?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="?android:attr/activatedBackgroundIndicator"> 

<ListView 
    android:id="@+id/listView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:divider="#ebebeb" 
    android:dividerHeight="1dip"/> 
</RelativeLayout> 
+1

它是你的LIST佈局。您需要將該背景參數設置爲LIST ITEM佈局的根元素,您將在適配器中膨脹到每個listView的行。 – udenfox

+0

如果您使用可繪製選擇器來指定顏色,請在列表項佈局上設置'android:background =「@ drawable/list_selector',然後在選擇器'item'中使用'android:state_activated =」true「'來識別該項目被激活時使用的背景顏色。 –