5

I have two number pickers, I want to get the value that user chose from thos number pickers. then convert them to String.

Any idea?

user2977338
  • 125
  • 2
  • 5
  • 11
  • Some documentation on NumberPicker for Android. http://developer.android.com/reference/android/widget/NumberPicker.html Also, this might help: http://stackoverflow.com/questions/9279785/how-to-use-numberpicker-widget-android-4-0 – Radnyx Nov 24 '13 at 22:22

1 Answers1

7

You can get current picked number by calling getValue(), eg. if you have myPicker, you can do this:

String value = "" + myPicker.getValue();

If you want to get the value when it's selected by user, you need to implement NumberPicker.OnValueChangeListener interface:

private class MyListener implements NumberPicker.OnValueChangeListener {
    @Override
    public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
        //get new value and convert it to String
        //if you want to use variable value elsewhere, declare it as a field 
        //of your main function
        String value = "" + newVal;
    }
}

Remember to set your listener, eg:

myPicker.setOnValueChangedListener(new MyListener());
Melquiades
  • 8,316
  • 1
  • 27
  • 40