If you want to give the user the choice of 0, 10, 20 and so on up to 90 you first have to initialize a string array of the correct size to these values. In this case the difference between MaxValue and MinValue properties +1 give the number of elements in the list.

You may have noticed that the array used to specify the values is a String array. What this means is that the NumberPicker, despite its name, can allow the user to pick from a list of arbitrary strings that you can set.

When it comes to retrieving the data you can use the getValue method which return an integer which is either the value the user picked if you are not using a String array for the values or it is the index in the String array of the value the user picked.

If you want to get a live update of the value the user selects you can use the OnValueChange event. The event handler

provides you with the NumberPicker object that the event occurred on as picker and the index of the old and new values. The only problem is getting that value from the String array that defined the values displayed which is probably not accessible from the event handler. The solution is to use the NumberPicker's getDisplayedValues which returns a String array of values.

For example to transfer the value to a TextView you first have to define a Listener object which you can do easily with the help of Android Studio's autocomplete:

If you do what you get is what you see in the Android Studio designer:

Multi-Digit Input

Finally if you want to create a multi-digit input - say hundreds, tens, units - then simply use three NumberPickers. This is more tricky than it first appears if you want to dynamically track the current value across more than one NumberPicker.

For example, to build a three-digit input you first need to place three NumberPickers on the design surface with ids numberPicker1, numberPicker2 and numberPicker3.

You could initialize each of the NumberPickers in turn but it is instructive to use an array of NumberPickers to do the job:

In this case we don't use any of the event method's parameters we simply get the three NumberPickers and get their DisplayValues as a String array and the current value using the index returned by getValue.

The only tricky but is building up the string of digits to be displayed in temp. If you aren't sure what is going on try changing the line that sets temp to read:

temp=temp+values[nps[i].getValue()];

In the jargon of math String concatenation is not commutative - in the jargon of programming it matters which end you stick something on to a String.

Of course as all three NumberPickers share the same set of values we really only need to getDisplayedValues once but this is more general. Also it is very obvious that part of the code are repeated and it would be better to refactor to create a function to get the three NumberPickers for example.

If you run the program you should be able to alter what is displayed in the TextView in a sensible three digit place value way: