I am making a number picker dialog having 2 number pickers, years and months. I want to show some default value in these 2 number picker, apart from 0, 0
Code::
final NumberPicker numberPickerYear = (NumberPicker) expDialog.findViewById(R.id.numberPickerYears);
final NumberPicker numberPickerMonth = (NumberPicker) expDialog.findViewById(R.id.numberPickerMonths);
numberPickerYear.setMaxValue(35);
numberPickerYear.setMinValue(0);
numberPickerYear.setWrapSelectorWheel(true);
numberPickerMonth.setMaxValue(11);
numberPickerMonth.setMinValue(0);
numberPickerMonth.setWrapSelectorWheel(true);
By default maxValue and minValue in NumberPicker is 0. So you need to set maxValue and minValue before using setValue.
numberPickerMonth.setValue(defaultQuanity);
READ Carefully:
void setValue (int value) Set the current value for the number picker.
- If the argument is less than the
getMinValue()
andgetWrapSelectorWheel()
is false the current value is set to thegetMinValue()
value.- If the argument is less than the
getMinValue()
andgetWrapSelectorWheel()
is true the current value is set to thegetMaxValue()
value.- If the argument is less than the
getMaxValue()
andgetWrapSelectorWheel()
is false the current value is set to thegetMaxValue()
value.- If the argument is less than the
getMaxValue()
andgetWrapSelectorWheel()
is true the current value is set to thegetMinValue()
value.
final NumberPicker numberPickerYear = (NumberPicker) expDialog.findViewById(R.id.numberPickerYears);
final NumberPicker numberPickerMonth = (NumberPicker) expDialog.findViewById(R.id.numberPickerMonths);
numberPickerYear.setMaxValue(35);
numberPickerYear.setMinValue(0);
numberPickerYear.setWrapSelectorWheel(true);
numberPickerYear.setValue(17);// here to set default value of
numberPickerMonth.setMaxValue(11);
numberPickerMonth.setMinValue(0);
numberPickerMonth.setWrapSelectorWheel(true);
numberPickerMonth.setValue(5);// here to set default value of numberPickerMonth
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With