How do you display a 2 digit NumberPicker in android?

illis69 picture illis69 · Nov 2, 2013 · Viewed 9.7k times · Source

I want to create a timer and since I couldn't create a digital interface that is editable for the user to set the time I want to use the NumberPicker. However the NumberPicker only displays 1 digit for the numbers between 0-9. How do you format the picker so that it will display two digits such as 01 02 03 and so forth.

Answer

Naveen Agrawal picture Naveen Agrawal · Nov 20, 2014
    numberPicker.setMaxValue(10);
    numberPicker.setMinValue(0);
    numberPicker.setFormatter(new NumberPicker.Formatter() {
        @Override
        public String format(int i) {
            return String.format("%02d", i);
        }
    });

This will do the trick!

enter image description here