获取浮点/双精度从NumberPicker [英] Getting float/double from NumberPicker

查看:264
本文介绍了获取浮点/双精度从NumberPicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 https://github.com/SimonVT/android-numberpicker 库和基准是https://developer.android.com/reference/android/widget/NumberPicker.html#getValue%28%29
现在两者,API级别11 NumberPicker返回getValue方法和int值也SimonVT numberpicker返回int值。

I am trying the https://github.com/SimonVT/android-numberpicker library and the reference is https://developer.android.com/reference/android/widget/NumberPicker.html#getValue%28%29 Now both, the API level 11 NumberPicker returns int value in getValue method and also the SimonVT numberpicker returns int value.

但我已经通过以下code设置在号码选择器双重价值:

But I had set double values in the number picker by using following code:

String[] nums = {"1","1.5","2","2.5","3","3.5","4","4.5","5","5.5","6","6.5","7","7.5","8","8.5","9"};

final NumberPicker listeningScorenp = (NumberPicker) findViewById(R.id.listeningScore);
listeningScorenp.setMaxValue(nums.length-1);
listeningScorenp.setMinValue(0);
listeningScorenp.setWrapSelectorWheel(false);
listeningScorenp.setDisplayedValues(nums);

现在我坚持了如何从NUmberPicker检索浮点/双精度值。

Now I am stuck with how to retrieve the float/double values from NUmberPicker.

推荐答案

我只是用你的code测试。的getValue()实际上返回选择(仅当您设置显示的值)的项目的索引。所有你需要做的是分析该字符串,你将有你想要的。

I just tested using your code. getValue() actually returns the index of the item selected (only when you set the displayed values). All you'll need to do is parse the string and you will have what you wanted.

String[] nums = {"1","1.5","2","2.5","3","3.5","4","4.5","5","5.5","6","6.5","7","7.5","8","8.5","9"};
int index = listeningScorenp.getValue();
String val = nums[index];
float selectedFloat = Float.parseFloat(val);

这篇关于获取浮点/双精度从NumberPicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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