我的意见没有得到承认

时间:2017-10-20 09:10:21

标签: android kotlin

所以我有这3个采摘者

val pickerHours = numberPickerHours as NumberPicker
val pickerMinutes = numberPicker as NumberPicker
val pickerSeconds = numberPickerSeconds as NumberPicker

我创建了一个监听器以获取它们的值,但我的验证是“正常工作”到它假设值没有改变的程度。因此,在我的选择器上选择的价值无关紧要,它没有做任何事情

有什么想法吗?

var timerString = ""
var timerString1 = ""
var timerString2 = ""
pickerHours.minValue = 0
pickerHours.maxValue = 100
pickerHours.wrapSelectorWheel = false
pickerHours.isEnabled = true

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

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

pickerHours.setOnValueChangedListener { picker, oldVal, newVal ->
    timerString = newVal.toString() + ":" + pickerMinutes.value.toString() + ":" + pickerSeconds.value.toString()
}
pickerMinutes.setOnValueChangedListener { picker, oldVal, newVal ->
    timerString = pickerHours.value.toString() + ":" + newVal + ":" + pickerSeconds.value
}
pickerSeconds.setOnValueChangedListener { picker, oldVal, newVal ->
    timerString = pickerHours.value.toString() + ":" + pickerMinutes.value.toString() + ":" + newVal
}

calculateBtn.setOnClickListener {
    when {
        timerString.isEmpty() && timerString1.isEmpty() && timerString2.isEmpty() && (distance.text.isNotEmpty() && pace.text.isNotEmpty()) ->
            calculatePace(null, distance.text.toString().toDouble(), pace.text.toString())

        distance.text.isEmpty() && (timerString.isNotEmpty() && timerString1.isNotEmpty() && timerString2.isNotEmpty() && pace.text.isNotEmpty()) ->
            calculatePace(timerString, null, pace.text.toString())

        (time.text.isNotEmpty() && distance.text.isNotEmpty()) ->
            calculatePace(timerString, distance.text.toString().toDouble(), null)


        else -> {
            Toast.makeText(this, "Please check fields",
                    Toast.LENGTH_SHORT).show()
        }
    }}

0 个答案:

没有答案