I have a range of values ​​and I need the NumberPicker default NumberPicker be in the middle of its values ​​...

I'm doing it like this

 NumberPicker pickerHeight = (NumberPicker) findViewById(R.id.pickerHeight); pickerHeight.setMaxValue(220); pickerHeight.setMinValue(130); pickerHeight.setValue(155); 

In the last line I specify the default value. But when I load onto the device, the default value is still at the lowest mark in my case at 130.

What am I doing wrong?

  • And if you add it here? pickerHeight.setWrapSelectorWheel(false); ? - YurySPb
  • No, this line simply does not allow the NumberPicker to rotate in a circle, and as soon as it reaches one of the limit values ​​for min or max , then there are no further values ​​... And it’s also strange on one NumberPicker that works that way, but on the other it’s just ignored and nothing does not happen ... Although the same thing is there, that there ... - Aleksey Timoshchenko
  • Those. If you create an empty project with an empty activity and in it there is only one picker to indicate in the markup and the operations you give to produce it, will it not work? Or do you hide any details? - Yuriy SPb
  • @YuriySPb In general, this situation created a clean project, put a picker in it, did everything as discussed and everything turned out ... I tried it on the main project again and nothing happened (I did everything as one to one), then I deleted the application from the phone and installed again and everything turned out ... Very strange ... I think this is because of the new Studio 2.1, it doesn’t seem to always update the code, but only XML files ... Well, I think so ... - Aleksey Timoshchenko
  • Well, maybe just in the new studio and the case - they promised to change the UI there without restarting the application on the device ... That's because I don’t rush to update it with 1.5)) - Yurii

1 answer 1

In general, this situation created a clean project, put a picker in it,

 <NumberPicker android:id="@+id/pickerWeight" android:layout_width="wrap_content" android:layout_height="0dp"/> 

Then set a minimum maximum and default value like so

 NumberPicker pickerHeight = (NumberPicker) findViewById(R.id.pickerHeight); pickerHeight.setMaxValue(220); pickerHeight.setMinValue(130); pickerHeight.setValue(155); 

and everything turned out ... I tried it on the main project again and nothing happened (I did everything one by one). Then I deleted the application from the phone and installed it again and everything turned out ... Very strange ... it seems to me because of the new 2.1 studio, it seems that the code doesn’t always update the XML files ... Well, I think so .. .