Android Numberpicker默认值未到 [英] Android Numberpicker default value not coming

查看:72
本文介绍了Android Numberpicker默认值未到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

加载数字选择器后,直到触摸默认值,屏幕上才会显示默认值.

When the numberpicker is loaded, the default value is not appearing on the screen until touched.

一经触摸,一切正常.任何帮助表示赞赏.

Once touched, everything works fine.Any help appreciated.

如果格式化程序已删除,它也可以正常工作.

Also if the formatter is removed, it works fine.

dialog.xml

dialog.xml

<NumberPicker
    android:id="@+id/number_picker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     />

<Button
    android:id="@+id/apply_button"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/number_picker"
    android:text="@string/ok_string" />

这是活动代码:

final NumberPicker np = (NumberPicker) d.findViewById(R.id.number_picker);
        np.setMaxValue(50);
        np.setMinValue(0);
        np.setWrapSelectorWheel(true);
        np.setOnValueChangedListener(this);
        np.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

        np.setFormatter(new NumberPicker.Formatter() {
            @Override
            public String format(int i) {
                if (i == 25)
                    return "0";
                else
                    return String.valueOf(i - 25);
            }
        });
        np.setValue(25);

预先感谢

推荐答案

该问题似乎是NumberPicker小部件中的错误.

The issue seems to a bug in NumberPicker widget.

我已经使用此处所述的方法2解决了该问题

And I have solved it using method 2 described here.

这篇关于Android Numberpicker默认值未到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆