Formatted value of NumberPicker disappears onClick

心不动则不痛 提交于 2020-01-04 09:17:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!