附加计时器的StringBuilder不起作用(Kotlin) [英] StringBuilder to append chronometer did not work (Kotlin)

查看:69
本文介绍了附加计时器的StringBuilder不起作用(Kotlin)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在每行上放置一个天文钟,但这没用.

I'm trying to put a chronometer on each line, but it didn't work.

我的输出:

我想要的东西:

val chrono = StringBuilder()  // Is there a ChronometerBuilder?

for (i in 0 until 4){
      chronoView.base = SystemClock.elapsedRealtime()
      chronoView.start()
      chrono.append(chronoView.base)   // I don't know what to include in the parameter

      chrono.append("\n\n")
}

chronoView.text = chrono

推荐答案

https://developer.android.com/reference/android/widget/Chronometer 是一种TextView. 计时码表每启动一秒都会写入一次(计时码表本身有一个计时器,并以默认格式mm:ss显示). 因此,如果您想写文字,则必须将其停止

https://developer.android.com/reference/android/widget/Chronometer is a kind of TextView. Chronometer writes every seconds if you starts it (Chronometer has a timer itself, and displays with default format mm:ss). So, if you want to write a text, you must stop it

如果要在活动中显示4个时钟,请使用4计时器.

If you want to show 4 clocks in your activity, use 4 Chronometer.

如果要在活动中显示4个文本,请使用另一个TextView

If you want to show 4 text in your activity, use another TextView

这篇关于附加计时器的StringBuilder不起作用(Kotlin)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆