NumberPicker does not stand out when disconnected

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.

+4
source share
3 answers

Well, without any additional feedback, I'm going to go and close it. Here is what I know:

This seems to be a bug introduced in Jellybean. I tested emulators, and the user interface works as expected in ICS and earlier. At the moment, I'm just going to sort this out and try to submit an official bug report.

+2
source

Try this way.

  NumberPicker npicker = (NumberPicker) findViewById(R.id.diceCountPicker1); npicker.setMaxValue(100); npicker.setMinValue(0); npicker.setOnValueChangedListener(new OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { // Conditions for Enable/Disable picker if (newVal == 0) { picker.setEnabled(false); } else if (oldVal == 0) { picker.setEnabled(true); } } }); 

It works well for me, and it behaves correctly with Enable / Disable according to the added conditions.

Thanks.

0
source

Setting android:enabled="false" in the NumberPicker and DatePicker xml layouts does not disable the controls for me on an Android 4.0.4 device. However, executing programmatically with setEnabled(false) works as expected.

0
source

All Articles