Added in API level 1

Chronometer


open class Chronometer : TextView
kotlin.Any
   ↳ android.view.View
   ↳ android.widget.TextView
   ↳ android.widget.Chronometer

Class that implements a simple timer.

You can give it a start time in the SystemClock#elapsedRealtime timebase, and it counts up from that, or if you don't give it a base time, it will use the time at which you call start.

The timer can also count downward towards the base time by setting setCountDown(boolean) to true.

By default it will display the current timer value in the form "MM:SS" or "H:MM:SS", or you can use setFormat to format the timer value into an arbitrary string.

Summary

Nested classes
abstract

A callback that notifies when the chronometer has incremented on its own.

XML attributes
android:countDown Specifies whether this Chronometer counts down or counts up from the base.
android:format Format string: if specified, the Chronometer will display this string, with the first "%s" replaced by the current timer value in "MM:SS" or "H:MM:SS" form.
Inherited XML attributes
Inherited constants
Public constructors
Chronometer(context: Context!)

Initialize this Chronometer object.

Chronometer(context: Context!, attrs: AttributeSet!)

Initialize with standard view layout information.

Chronometer(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Initialize with standard view layout information and style.

Chronometer(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open CharSequence!

open Long

Return the base time as set through setBase.

open CharSequence!

open String!

Returns the current format string as set through setFormat.

open Chronometer.OnChronometerTickListener!

open Boolean

open Boolean

open Unit
setBase(base: Long)

Set the time that the count-up timer is in reference to.

open Unit
setCountDown(countDown: Boolean)

Set this view to count down to the base instead of counting up from it.

open Unit
setFormat(format: String!)

Sets the format string used for display.

open Unit

Sets the listener to be called when the chronometer changes.

open Unit

Start counting up.

open Unit

Stop counting up.

Protected methods
open Unit

open Unit
onVisibilityChanged(changedView: View, visibility: Int)

open Unit

Inherited functions
Inherited properties

XML attributes

android:countDown

android:countDown
Specifies whether this Chronometer counts down or counts up from the base. If not specified this is false and the Chronometer counts up.

May be a boolean value, such as "true" or "false".

android:format

android:format
Format string: if specified, the Chronometer will display this string, with the first "%s" replaced by the current timer value in "MM:SS" or "H:MM:SS" form. If no format string is specified, the Chronometer will simply display "MM:SS" or "H:MM:SS".

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

Public constructors

Chronometer

Added in API level 1
Chronometer(context: Context!)

Initialize this Chronometer object. Sets the base to the current time.

Chronometer

Added in API level 1
Chronometer(
    context: Context!,
    attrs: AttributeSet!)

Initialize with standard view layout information. Sets the base to the current time.

Chronometer

Added in API level 1
Chronometer(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

Initialize with standard view layout information and style. Sets the base to the current time.

Chronometer

Added in API level 21
Chronometer(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

getAccessibilityClassName

Added in API level 23
open fun getAccessibilityClassName(): CharSequence!

getBase

Added in API level 1
open fun getBase(): Long

Return the base time as set through setBase.

getContentDescription

Added in API level 4
open fun getContentDescription(): CharSequence!
Return
CharSequence! the content description

getFormat

Added in API level 1
open fun getFormat(): String!

Returns the current format string as set through setFormat.

getOnChronometerTickListener

Added in API level 3
open fun getOnChronometerTickListener(): Chronometer.OnChronometerTickListener!
Return
Chronometer.OnChronometerTickListener! The listener (may be null) that is listening for chronometer change events.

isCountDown

Added in API level 24
open fun isCountDown(): Boolean
Return
Boolean whether this view counts down

isTheFinalCountDown

Added in API level 26
open fun isTheFinalCountDown(): Boolean
Return
Boolean whether this is the final countdown

setBase

Added in API level 1
open fun setBase(base: Long): Unit

Set the time that the count-up timer is in reference to.

Parameters
base Long: Use the SystemClock#elapsedRealtime time base.

setCountDown

Added in API level 24
open fun setCountDown(countDown: Boolean): Unit

Set this view to count down to the base instead of counting up from it.

Parameters
countDown Boolean: whether this view should count down

See Also

setFormat

Added in API level 1
open fun setFormat(format: String!): Unit

Sets the format string used for display. The Chronometer will display this string, with the first "%s" replaced by the current timer value in "MM:SS" or "H:MM:SS" form. If the format string is null, or if you never call setFormat(), the Chronometer will simply display the timer value in "MM:SS" or "H:MM:SS" form.

Parameters
format String!: the format string.

setOnChronometerTickListener

Added in API level 3
open fun setOnChronometerTickListener(listener: Chronometer.OnChronometerTickListener!): Unit

Sets the listener to be called when the chronometer changes.

Parameters
listener Chronometer.OnChronometerTickListener!: The listener.

start

Added in API level 1
open fun start(): Unit

Start counting up. This does not affect the base as set from setBase, just the view display. Chronometer works by regularly scheduling messages to the handler, even when the Widget is not visible. To make sure resource leaks do not occur, the user should make sure that each start() call has a reciprocal call to stop.

stop

Added in API level 1
open fun stop(): Unit

Stop counting up. This does not affect the base as set from setBase, just the view display. This stops the messages to the handler, effectively releasing resources that would be held as the chronometer is running, via start.

Protected methods

onDetachedFromWindow

Added in API level 1
protected open fun onDetachedFromWindow(): Unit

onVisibilityChanged

Added in API level 8
protected open fun onVisibilityChanged(
    changedView: View,
    visibility: Int
): Unit
Parameters
changedView View: The view whose visibility changed. May be this or an ancestor view. This value cannot be null.
visibility Int: The new visibility, one of VISIBLE, INVISIBLE or GONE. Value is android.view.View#VISIBLE, android.view.View#INVISIBLE, or android.view.View#GONE

onWindowVisibilityChanged

Added in API level 1
protected open fun onWindowVisibilityChanged(visibility: Int): Unit
Parameters
visibility Int: The new visibility of the window. Value is android.view.View#VISIBLE, android.view.View#INVISIBLE, or android.view.View#GONE