How to set timer in android?

后端 未结 21 907
渐次进展
渐次进展 2020-11-22 00:51

Can someone give a simple example of updating a textfield every second or so?

I want to make a flying ball and need to calculate/update the ball coordinates every se

21条回答
  •  爱一瞬间的悲伤
    2020-11-22 01:35

    for whom wants to do this in kotlin:

    val timer = fixedRateTimer(period = 1000L) {
                val currentTime: Date = Calendar.getInstance().time
                runOnUiThread {
                    tvFOO.text = currentTime.toString()
                }
            }
    

    for stopping the timer you can use this:

    timer.cancel()
    

    this function has many other options, give it a try

提交回复
热议问题