Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closed - Setting NumberPicker default value

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

enter image description here

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);
like image 340
Adarsh Raj Avatar asked Aug 16 '16 08:08

Adarsh Raj


2 Answers

By default maxValue and minValue in NumberPicker is 0. So you need to set maxValue and minValue before using setValue.

numberPickerMonth.setValue(defaultQuanity);
like image 178
Riyaz Parasara Avatar answered Nov 15 '22 13:11

Riyaz Parasara


READ Carefully:

void setValue (int value) Set the current value for the number picker.

  1. If the argument is less than the getMinValue() and getWrapSelectorWheel() is false the current value is set to the getMinValue() value.
  2. If the argument is less than the getMinValue() and getWrapSelectorWheel() is true the current value is set to the getMaxValue() value.
  3. If the argument is less than the getMaxValue() and getWrapSelectorWheel() is false the current value is set to the getMaxValue() value.
  4. If the argument is less than the getMaxValue() and getWrapSelectorWheel() is true the current value is set to the getMinValue() 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
like image 23
Sohail Zahid Avatar answered Nov 15 '22 13:11

Sohail Zahid