1

所以我有一些textViews他们的输入是数字,但为了不易出错,我想将其替换为numberPickers.

我做了什么

  • TextViews工作
  • NumberPickers工作
  • 任何数学和计算工作

我需要什么

  • 更换输入法

  • 这就是我的textViews

    when {
    
            time.text.isEmpty() && (distance.text.isNotEmpty() && pace.text.isNotEmpty()) ->
                calculatePace(null, distance.text.toString().toDouble(), pace.text.toString())
    
            distance.text.isEmpty() && (time.text.isNotEmpty() && pace.text.isNotEmpty()) ->
                calculatePace(time.text.toString(), null, pace.text.toString())
    
            pace.text.isEmpty() && (time.text.isNotEmpty() && distance.text.isNotEmpty()) ->
                calculatePace(time.text.toString(), distance.text.toString().toDouble(), null)
    
    
            else -> {
                Toast.makeText(this, "Please check fields",
                        Toast.LENGTH_SHORT).show()
            }
        }
    

这些是我的pickers

    val pickerMinutes = numberPicker as NumberPicker
    val pickerSeconds = numberPickerSeconds as NumberPicker
    pickerMinutes.minValue = 0
    pickerMinutes.maxValue = 60
    pickerMinutes.wrapSelectorWheel = false
    pickerMinutes.isEnabled = true

    pickerSeconds.minValue = 0
    pickerSeconds.maxValue = 60
    pickerSeconds.wrapSelectorWheel = false
    pickerSeconds.isEnabled = true

任何帮助将不胜感激

谢谢

4

1 回答 1

0

如果您查看NumberPicker API,您会看到有一个getValue()返回选定值的方法,即 int 返回类型。您可以使用toDouble(),因为您的计算方法采用双精度型

NB 因为 NumberPicker 总是使用整数我认为你可以修改你的计算方法,因为它永远不会从 NumberPicker 获得 Double

请确认,如果我没有得到你想要的

于 2017-10-18T09:31:10.163 回答