我们的应用程序的用户应该能够调整浮点数.目前,我在ArrayAdapter中填充了所有可能的值并将其附加到微调器上.
这个解决方案并不能满足我们的期望,因为旋转器下拉框太高了.有没有更好的办法?我在看Numberpicker - 但这似乎只适用于Integer值.
有任何想法吗?
谢谢!
加载数字选择器后,触摸前默认值不会出现在屏幕上.
一旦感动,一切正常.任何帮助赞赏.
此外,如果格式化程序被删除,它工作正常.

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" />
Run Code Online (Sandbox Code Playgroud)
这是活动代码:
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);
Run Code Online (Sandbox Code Playgroud)
提前致谢
我正在尝试在 Android 中创建一个数字选择器,但轮子只增加 1。我想增加 0.1。我在网上查过,但我发现一个格式化的浮动数组禁用了轮子。请帮助和抱歉语法,我正在学习。