作用域: - 使用重寫ArrayAdapter; - 使用選擇器; - 使用isEnabled禁用項目。使用選擇器和isEnabled禁用列表視圖項目()
目標: - 禁用某些列表項並通過選擇器加載禁用的狀態視圖。
問題: - 一切正常(自定義視圖,選擇的重點不突出,focuesd並按下狀態),但已禁用的項目不爲禁用狀態使用選擇。
調查:當我使用isEnabled禁用列表視圖中的某些項時層次結構查看器顯示禁用的項目不可聚焦,不可點擊但啓用(!)。
難道是缺陷還是缺少什麼東西?
P.S.實際上,文檔說,isEnabled不會爲列表項目執行setEnabled(false),它會使其成爲分隔符(?)對象。 P.P.S我也嘗試使用if語句將我的View(在getView中)設置爲isEnabled(false)。但它只適用於重點項目?
我的選擇是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Disabled -->
<item
android:state_enabled="false"
android:textColor="@color/greyDark"
android:drawable="@drawable/list_item_disabled" />
<!-- Pressed -->
<item
android:state_enabled="true"
android:state_pressed="true"
android:textColor="@android:color/white"
android:drawable="@drawable/list_item_pressed" />
<!-- Focused -->
<item
android:state_enabled="true"
android:state_focused="true"
android:textColor="@android:color/white"
android:drawable="@drawable/list_item_focused" />
<!-- Default -->
<item
android:state_enabled="true"
android:drawable="@drawable/list_item_unfocused" />
</selector>
請注意未來的讀者:不要做我所做的事情,並假設我只需要第一部分,因爲我的XML佈局文件中沒有嵌套佈局! – cqcallaw