Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numberPicker format while editing

Tags:

android

I'm trying to use NumberPicker to enter values in range 5.0..30.0, with step 0.1. So I set up its range as 50..300 and added a formatter. The upper and lower values are represented as I want, but the current one is represented without decimal point, like 200, and it confuses much.

Which listener should I add (and where) to force NumberPicker always format the current value? I tried to disable focusable, to disable children focusable, to set children[0] text using my formatter upon focus change… Is that possible at all?

like image 868
gluk47 Avatar asked Mar 15 '26 01:03

gluk47


2 Answers

Missed that: setDisplayedValues. That's what I needed.

like image 180
gluk47 Avatar answered Mar 18 '26 11:03

gluk47


Here is the workaround: instead of setting mWidget.setFormatter(formatter),

String[] displayedValues = new String[mWidget.getMaxValue()-mWidget.getMinValue()+1];
for (int number = mWidget.getMinValue(); number<=mWidget.getMaxValue(); number++) {
    displayedValues[number-mWidget.getMinValue()] = formatter.format(number);
}
mWidget.setDisplayedValues(displayedValues);
like image 34
Alex Cohn Avatar answered Mar 18 '26 11:03

Alex Cohn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!