【问题标题】:Calling countDownTimer调用 countDownTimer
【发布时间】:2017-10-09 07:02:39
【问题描述】:

如何在 onResume() 中调用我的 CountDownTimer?

private fun countDownTime(timeOut: Long) {
    object : CountDownTimer(timeOut, 1000) {
        override fun onTick(millisUntilFinished: Long) {
            actionWarning.text = "Please wait: " + millisUntilFinished / 1000
        }
        override fun onFinish() {
        }
    }.start()
}

【问题讨论】:

  • 您必须更具体地说明您要在这里实现的目标。
  • 在 onResume() 方法中调用你的方法 countDownTime(1000) 还是你的意思?

标签: android methods kotlin


【解决方案1】:

似乎您需要将CountDownTimer 提取到一个字段:

class YourClass {

    val timer = object : CountDownTimer(timeOut, 1000) {
            override fun onTick(millisUntilFinished: Long) {
                actionWarning.text = "Please wait: " + millisUntilFinished / 1000
            }
            override fun onFinish() {
            }
        }

    private fun countDownTime(timeOut: Long) {
      timer.start()
    }

    fun onResume() {
      timer.whatever()
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多