所以我有一些textViews
,他們的輸入是數字,但爲了不太容易出錯我想用numberPickers
來代替它。替換textView for NumberPicker - Android
我做了什麼
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 –
嗨對不起,我已經完成了計算(功能)。但目前的輸入是textViews,我想將它們替換爲數字選擇器:) – Joedk
如果您需要輸入爲數字,則可以將EditText inputType屬性設置爲「number」。 「android:inputType =」number「 – Rachit