I believe that maybe I found an error in the Android user interface, but I would like to make sure that I am not doing anything wrong. Here is a simplified version of the code that I run that causes the problem. This listener is installed in a specific NumberPicker in my user interface, and it correctly disables / enables things, but if the user changes the value of one of the other NumberPickers, which he disables, it behaves a little strange.
It still correctly disables input, but it does not perform a gray value, making it look like it is still on. Is this intended? Am I doing something wrong?
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); } } };
Let me know if there is a better way to do this, or if this is a legitimate mistake. If this is a mistake, is there a way around it?
Edit: Here is the definition of diceCountPicker1 in XML:
<NumberPicker android:id="@+id/diceCountPicker1" android:layout_width="48dp" android:layout_height="128dp" android:descendantFocusability="blocksDescendants" />
Edit 2:
I tested this in emulators and confirmed that the problem did not exist until Jellybean (4.1). It works correctly in ICS. This is annoying. But I can live with it for now. I will leave this open to potential ways to get around the error, but it seems to me that this is a real error, and I doubt that it can be fixed.
source share