Search code examples
androidkotlinlocaltime

how to make localtime.now a continuous function that updates automatically?


As the title says, How could I make that LocalTime.now update continuously, essentially becoming somewhat into a clock?

    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.

Solution

  • Use TextClock This shows the time and updates it automatically you don't have to do anything, please refer to see in detail.

    <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