NumberPicker is the stock Android widget for choosing a value from a range with an up/down spinner. It is handy for quantities, durations, and settings, and a little configuration goes a long way toward making it feel polished.
Key takeaways
- Set min, max, and value to define the selectable range.
- Use a formatter for labels like '01' or '5 min' instead of raw numbers.
- Listen for value changes to drive the rest of your UI.
Basic setup
Add a NumberPicker to your layout and set its minValue, maxValue, and current value in code. The widget handles the spinner UI and wrapping behavior, so you mostly configure the range and react to changes.
Formatting and wrapping
A setFormatter lets you display values with padding or units — '01'..'12' for hours, or '5 min' increments — without changing the underlying integer. setWrapSelectorWheel controls whether the list loops at the ends.
Reacting to selection
Register an OnValueChangeListener to get the old and new values as the user scrolls, and update dependent state or other pickers accordingly. For Compose UIs, you would build an equivalent picker or wrap this view, but in the View system NumberPicker is the quickest path.