TimePicker

open class TimePicker : Picker
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.FrameLayout
   ↳ androidx.leanback.widget.picker.Picker
   ↳ androidx.leanback.widget.picker.TimePicker

TimePicker is a direct subclass of Picker.

This class is a widget for selecting time and displays it according to the formatting for the current system locale. The time can be selected by hour, minute, and AM/PM picker columns. The AM/PM mode is determined by either explicitly setting the current mode through setIs24Hour(boolean) or the widget attribute is24HourFormat (true for 24-hour mode, false for 12-hour mode). Otherwise, TimePicker retrieves the mode based on the current context. In 24-hour mode, TimePicker displays only the hour and minute columns.

This widget can show the current time as the initial value if useCurrentTime is set to true. Each individual time picker field can be set at any time by calling setHour(int), setMinute(int) using 24-hour time format. The time format can also be changed at any time by calling setIs24Hour(boolean), and the AM/PM picker column will be activated or deactivated accordingly. R.attr#is24HourFormat R.attr#useCurrentTime

Summary

Public constructors
<init>(context: Context!, attrs: AttributeSet!)

Constructor called when inflating a TimePicker widget.

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Constructor called when inflating a TimePicker widget.

Public methods
open Unit
onColumnValueChanged(columnIndex: Int, newValue: Int)

open Unit
setHour(hour: Int)

Sets the currently selected hour using a 24-hour time.

open Int

Returns the currently selected hour using 24-hour time.

open Boolean

open Unit
setIs24Hour(is24Hour: Boolean)

Sets whether this widget displays a 24-hour mode or a 12-hour mode with an AM/PM picker.

open Unit
setMinute(minute: Int)

Sets the currently selected minute.

open Int

Returns the currently selected minute.

open Boolean

Only meaningful for a 12-hour time.

Inherited functions

Public constructors

<init>

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

Constructor called when inflating a TimePicker widget. This version uses a default style of 0, so the only attribute values applied are those in the Context's Theme and the given AttributeSet.

Parameters
context Context!: the context this TimePicker widget is associated with through which we can access the current theme attributes and resources
attrs Context!: the attributes of the XML tag that is inflating the TimePicker widget

<init>

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

Constructor called when inflating a TimePicker widget.

Parameters
context Context!: the context this TimePicker widget is associated with through which we can access the current theme attributes and resources
attrs Context!: the attributes of the XML tag that is inflating the TimePicker widget
defStyleAttr Context!: An attribute in the current theme that contains a reference to a style resource that supplies default values for the widget. Can be 0 to not look for defaults.

Public methods

onColumnValueChanged

open fun onColumnValueChanged(columnIndex: Int, newValue: Int): Unit

setHour

open fun setHour(hour: Int): Unit

Sets the currently selected hour using a 24-hour time.

Parameters
hour Int: the hour to set, in the range (0-23)

See Also

getHour

open fun getHour(): Int

Returns the currently selected hour using 24-hour time.

Return
Int: the currently selected hour in the range (0-23)

See Also

is24Hour

open fun is24Hour(): Boolean
Return
Boolean: true if this widget displays time in 24-hour mode, false otherwise.

setIs24Hour

open fun setIs24Hour(is24Hour: Boolean): Unit

Sets whether this widget displays a 24-hour mode or a 12-hour mode with an AM/PM picker.

Parameters
is24Hour Boolean: true to display in 24-hour mode, false ti display in 12-hour mode with AM/PM.

See Also

setMinute

open fun setMinute(minute: Int): Unit

Sets the currently selected minute.

Parameters
minute Int: the minute to set, in the range (0-59)

See Also

getMinute

open fun getMinute(): Int

Returns the currently selected minute.

Return
Int: the currently selected minute, in the range (0-59)

See Also

isPm

open fun isPm(): Boolean

Only meaningful for a 12-hour time.

Return
Boolean: true if the currently selected time is in PM, false if the currently selected time in in AM.