Using NumberPicker Widget with Strings

All we need is an easy explanation of the problem, so here it is.

Is there a way to use the Android NumberPicker widget for choosing strings instead of integers?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

NumberPicker picker = new NumberPicker(this);
picker.setDisplayedValues( new String[] { "Belgium", "France", "United Kingdom" } );

Method 2

NumberPicker numberPicker = new NumberPicker(this);
String[] arrayString= new String[]{"hakuna","matata","timon","and","pumba"};

numberPicker.setFormatter(new NumberPicker.Formatter() {
  public String format(int value) {
    // TODO Auto-generated method stub
    return arrayString[value];

hope that helps!

Method 3

String value = String.valueOf(picker.getValue());

You could mean something else, but it isn’t very clear what you mean.


You can fake it by setting your own formatter:

CountryFormatter implements Formatter {
    public String toString(int value) {
        switch(value) {
            case 0:
                return "England";
            case 1:
                return "France";
        return "Unknown";

picker.setFormatter(new CountryFormatter());

getValue() will still return an int, so you probably want to map the names of countries to their ids.

The implementation of NumberPicker has:

public void setRange(int start, int end, String[] displayedValues)

Which seems to do a better job of what you want then the above formatter.. although it isn’t mentioned in the documentation so probably isn’t part of the public api

Method 4

try this solution, may help you

    NumberPicker pickers = new NumberPicker(this);
    String[] arrayPicker= new String[]{"abc","def","ghi","jkl","mno"};

    //set min value zero
    //set max value from length array string reduced 1
    pickers.setMaxValue(arrayPicker.length - 1);
    //implement array string to number picker
    //disable soft keyboard
    //set wrap true or false, try it you will know the difference

    //create button to test selected text string
    btnPicker.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            //get position (int) from number picker
            int pos = pickers.getValue();
            //get string from number picker and position
            String selecPicker = arrayPicker[pos];  
            //test toast to get selected text string
            Toast.makeText(context, selecPicker , Toast.LENGTH_SHORT).show();


Method 5

This worked for me.

public class YourClassName extends AppCompatActivity {

NumberPicker picker = null;

protected void onCreate(Bundle savedInstanceState) {

    picker = (NumberPicker) findViewById(;

    picker.setDisplayedValues(new String[]{"English", "French","Kiswahili","عربى"});

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply