how to change format of chronometer?

后端 未结 7 2321
攒了一身酷
攒了一身酷 2020-12-14 18:25

One of my problem is of changing the format of chronometer in android. i have the problem that chronometer shows its time in 00:00 format and i want it to come in 00:00:00 f

7条回答
  •  失恋的感觉
    2020-12-14 19:23

    In Kotlin, found a better solution with no memory allocation for the String every second

    cm_timer.format = "00:%s"
    cm_timer.setOnChronometerTickListener({ cArg ->
                val elapsedMillis = SystemClock.elapsedRealtime() - cArg.base
                if (elapsedMillis > 3600000L) {
                    cArg.format = "0%s"
                }
                else {
                    cArg.format = "00:%s"
                }
            })
    

    where cm_timer is Chronometer

提交回复
热议问题