我相信我可能在Android UI中發現了一個錯誤,但我想確保我沒有做錯什麼。這裏是我正在運行的代碼的簡化版本,導致了這個問題。這個監聽器在我的UI中被設置在一個特定的NumberPicker上,並且它正確地禁用/啓用了一些東西,但是如果用戶改變了它禁用的其他NumberPicker的值,它的行爲有點奇怪。NumberPicker在禁用時不灰色
它仍然正確地禁用了輸入,但它未能灰顯該值,使其看起來仍然處於啓用狀態。這是打算?難道我做錯了什麼?
NumberPicker.OnValueChangeListener diceChangeListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
View parent = (View) picker.getParent();
if (newVal == 0) {
((NumberPicker) parent.findViewById(R.id.diceCountPicker1)).setEnabled(false);
} else if (oldVal == 0) {
((NumberPicker) parent.findViewById(R.id.diceCountPicker1)).setEnabled(true);
}
}
};
讓我知道是否有更好的方法來做到這一點,或者如果這是一個合法的錯誤。如果它是一個錯誤,是否有辦法解決它?
編輯:這是在XML中diceCountPicker1的定義:
<NumberPicker
android:id="@+id/diceCountPicker1"
android:layout_width="48dp"
android:layout_height="128dp"
android:descendantFocusability="blocksDescendants"
/>
編輯2:
我在模擬器進行了測試,證實該問題不傑利貝恩之前存在(4.1) 。它在ICS中正常工作。這是...煩人。但我現在可能能夠忍受它。我會把這個問題留給潛在的方法來解決這個bug,但是它在我看來就像一個真正的bug,我懷疑它可以被修復。
你可以發佈一些佈局代碼,以便如何在xml文件中聲明你的'diceCountPicker1'嗎? –
使用NumberPicker的XML更新了問題。 – Utoxin
查看下面發佈的解決方案。嘗試一下,它適合我。謝謝。 –