【发布时间】:2017-10-18 08:50:22
【问题描述】:
所以我有一些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
任何帮助将不胜感激
谢谢
【问题讨论】:
-
不太清楚你想要什么?据我所知,您是否希望输入字段作为数字选择器而不是 TextView 并且需要相同的计算,是这样吗? @Joedk
-
嗨对不起,我已经完成了计算(函数)。但目前输入是文本视图,我想将它们替换为数字选择器:)
-
如果您只需要输入数字,您可以将 EditText inputType 属性设置为“数字”。 "android:inputType="数字"
-
我知道,但我需要用户 numberPicker(因为我在问题中提到的原因),以避免用户输入错误,因为这涉及时间,所以我总是需要:分隔符
标签: android kotlin android-number-picker