问题
My NumberPicker in setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS)
mode and the setWrapSelectorWheel(false)
is turned off.
I formatted my Numberpicker with a simple formatter:
mNumberPicker.setFormatter(new NumberPicker.Formatter() {
@Override
public String format(int value) {
return TextUtils.makeQuatityString(getContext(), value, R.plurals.nWeek);
}
});
Example output: 4 Weeks, where 4 is the value.
The NumberPicker is in a Dialog and after a short click on the value, the "Weeks" disappear, the "4" stays. Now, after a longer click, the formatted text re-appears.
Does anybody now how to fix this?
回答1:
Looks like this is a bug Others are facing this issue too. Check this question.
This worked for me. I tested at API 24.
try {
Field f = NumberPicker.class.getDeclaredField("mInputText");
f.setAccessible(true);
EditText inputText = (EditText) f.get(yourPicker);
inputText.setFilters(new InputFilter[0]);
} catch (Exception e) {
e.printStackTrace();
}
来源:https://stackoverflow.com/questions/42458566/formatted-value-of-numberpicker-disappears-onclick