【问题标题】:how to setValue in Two NumberPickers from float value如何从浮点值中设置两个 NumberPicker 中的值
【发布时间】:2017-02-03 15:35:47
【问题描述】:

我有两个号码选择器

NumberPicker np1 = (NumberPicker)container.findViewById(R.id.np1);
NumberPicker np2 = (NumberPicker)container.findViewById(R.id.np2);

示例: enter image description here

这个:

String sValue = np1.getValue() + "." + np2.getValue();

textView.settext(sValue);

返回例如 60.5

但我不知道如何把浮点值放回去

float f = (float)60.5;

进入我的两个 numberPickers。请帮忙。

【问题讨论】:

    标签: numberpicker


    【解决方案1】:

    如果您的数字只有一位小数,那么您可以执行以下操作:

    float f = 60.5f;
    
    var left = Math.Truncate(f);    
    var right = (f-left) * 10;
    
    np1.setValue(left);
    np2.setValue(right);
    

    【讨论】:

    • 谢谢!!!我的意思是安卓。但是你的回答帮助了我。浮动 f = 60.5f; int左=(int)f;浮动 f1 = (f - (float)left) * 10; int right = (int)f1;
    猜你喜欢
    • 1970-01-01
    • 2014-08-04
    • 2015-08-08
    • 1970-01-01
    • 2015-10-30
    • 2012-09-01
    • 1970-01-01
    • 2014-06-07
    • 2016-12-22
    相关资源
    最近更新 更多