我有這樣的列表視圖:Android的ListView項不顯示所選的顏色
<ListView
android:id="@+id/contactsView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/searchButton"
android:divider="@color/DarkGoldenrod"
android:dividerHeight="0.1dp"
android:listSelector="@drawable/list_selector"
android:choiceMode="singleChoice" />
這是list_selector
代碼:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:drawable/myRedColor" android:state_pressed="true"/>
<item android:drawable="@android:drawable/myBlueColor" android:state_selected="true"/>
<item android:drawable="@android:drawable/myGreenColor"/>
</selector>
在我的主要活動課我已經把以下內容:
contactsView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
arg1.setSelected(true);
selectedContactIndex = (int) arg3;
}
});
contactsView
是列表視圖,我已經確認它正在被選中但顏色不停留。我點擊它,它會改變然後改回來。任何想法爲什麼?