(Android) NumberPicker with leading zero

By | June 21, 2014

Set your number picker to show leading zeros by applying a formatter to it.
Example is using an anonymous instance, but of course it doesn’t have to.

myNumberPicker.setFormatter(new NumberPicker.Formatter() {
			@Override
			public String format(int value) {
				return String.format("%02d", value);
			}
		});

For %02d this goes:

  • 0 for filling with zeros
  • 2 for length of 2

3 thoughts on “(Android) NumberPicker with leading zero

  1. John

    Many thanks, I’ve been struggling with how to do this for the last day.
    Cheers.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *