Closed - Setting NumberPicker default value

Adarsh Raj picture Adarsh Raj · Aug 16, 2016 · Viewed 9k times · Source

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);

Answer

Riyaz Parasara picture Riyaz Parasara · Aug 16, 2016

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

numberPickerMonth.setValue(defaultQuanity);