How do I get the value of setFormatter using numberPicker?

Allart :

Im using a numberPicker and found the answer to display 00, 01, 02... in my numberPicker, i used setFormatter. The problem is that when i call getValue() i will get 0, 1, 2... I need to get 00, 01, 02... so that i can display it as text in a different View. Is there anyway of doing this? With or without setFormatter.

I've searched online and checked if anyone else had the same problem but could't find anything :(. Also thought about using a timePicker/datePicker but then i face the same problems.

numberPickerLeftHours.setMinValue(0);
numberPickerLeftHours.setMaxValue(23);

//Put a extra 0 in front of single numbers.
numberPickerLeftHours.setFormatter(new NumberPicker.Formatter() {
     @SuppressLint("DefaultLocale")
     @Override
     public String format(int value) {
           Log.i(TAG, "onCreate: numberPickerLeftHours.getValue(): " + numberPickerLeftHours.getValue());
           return String.format("%02d", value);
     }
});

So my Log.i(); value is 0, 1, 2... but i need 00, 01 ... 09, 10, 11, 12 till 23.

Yupi :

Sorry my bad in comment so the code would look like similar to this:

numberPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker numberPicker, int i, int i1) {
            String formated = String.format("%02d", numberPicker.getValue());
            Log.d("PickerValue", formated);
            yourTextView.setText(formated);

        }
    });

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=69564&siteId=1