【问题标题】:how to make localtime.now a continuous function that updates automatically?如何使 localtime.now 成为自动更新的连续函数?
【发布时间】:2021-08-06 03:41:05
【问题描述】:

正如标题所说,我怎样才能让 LocalTime.now 不断更新,基本上变成了一个时钟?

    var current  = LocalTime.now()
    Current.text = current.toString()
    //Current is the textView id in xml
    // this currently prints out what the local time is at app launch.

【问题讨论】:

  • 您必须定期更新它,从这个意义上说,没有“连续函数”之类的东西。所以也许考虑运行重复的、延迟的代码并从那里开始。

标签: android kotlin localtime


【解决方案1】:

使用 TextClock 这会显示时间并自动更新,您无需执行任何操作,请参阅详细信息。

<TextClock
    android:id="@+id/textClock"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:format12Hour="hh:mm:ss a" />

https://developer.android.com/reference/android/widget/TextClock.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-26
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    • 2013-04-28
    • 2020-01-25
    • 1970-01-01
    • 2018-07-03
    相关资源
    最近更新 更多