【问题标题】:Kotlin setText error in countdown timer: None of the following functions can be called with the arguments supplied:倒数计时器中的 Kotlin setText 错误:不能使用提供的参数调用以下函数:
【发布时间】:2020-10-07 19:48:24
【问题描述】:
val CountDownTimer=object: CountDownTimer(10000,1000){
            override fun onTick(millisUntilFinished: Long) {
                txtTimer.setText(millisUntilFinished/1000)
            }

            override fun onFinish() {
                Toast.makeText(this@Play_Area,"Time up",Toast.LENGTH_SHORT).show()
            }
        }
        CountDownTimer.start()

我正在将倒计时传递给 onTick 函数中的 xml,它在 setText 中显示以下错误:

以下函数都不能使用提供的参数调用: public final fun setText(p0: CharSequence!): android.widget.TextView 中定义的单位 public final fun setText(p0: Int): android.widget.TextView中定义的单位

请帮忙...

【问题讨论】:

  • txtTimer.setText((millisUntilFinished/1000).toString())

标签: android xml kotlin timer settext


【解决方案1】:

这是因为您在字符串输入类型函数中设置长值。只需将您的长值与字符串连接起来即可在您的 TextView 上显示它,例如

textView.setText("" + millisUntilFinished/1000)

希望得到问题的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-30
    • 1970-01-01
    • 1970-01-01
    • 2018-10-03
    • 2019-06-19
    • 1970-01-01
    相关资源
    最近更新 更多