Added in API level 1

TimePicker

open class TimePicker : FrameLayout
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.FrameLayout
   ↳ android.widget.TimePicker

A widget for selecting the time of day, in either 24-hour or AM/PM mode.

For a dialog using this view, see android.app.TimePickerDialog. See the Pickers guide for more information.

Summary

Nested classes
abstract

The callback interface used to indicate the time has been adjusted.

XML attributes
android:timePickerMode Defines the look of the widget.
Inherited XML attributes
Inherited constants
Public constructors
TimePicker(context: Context!)

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

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

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

Public methods
open Unit

open Unit

open CharSequence!

open Int

Describes the autofill type of this view, so an android.service.autofill.AutofillService can create the proper AutofillValue when autofilling the view.

open AutofillValue?

open Int

open Int

open Int

open Int

Returns the currently selected hour using 24-hour time.

open Int

Returns the currently selected minute.

open Boolean

open Boolean

open Unit
setCurrentHour(currentHour: Int)

Sets the currently selected hour using 24-hour time.

open Unit
setCurrentMinute(currentMinute: Int)

Sets the currently selected minute.

open Unit
setEnabled(enabled: Boolean)

open Unit
setHour(hour: Int)

Sets the currently selected hour using 24-hour time.

open Unit
setIs24HourView(is24HourView: Boolean)

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

open Unit
setMinute(minute: Int)

Sets the currently selected minute.

open Unit

Set the callback that indicates the time has been adjusted by the user.

open Boolean

Validates whether current input by the user is a valid time based on the locale.

Protected methods
open Unit

open Parcelable?

Inherited functions
Inherited properties

XML attributes

android:timePickerMode

android:timePickerMode
Defines the look of the widget. Prior to the L release, the only choice was spinner. As of L, with the Material theme selected, the default layout is clock, but this attribute can be used to force spinner to be used instead.

Must be one of the following constant values.

Constant Value Description
clock 2 Time picker with clock face to select the time.
spinner 1 Time picker with spinner controls to select the time.

Public constructors

TimePicker

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

TimePicker

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

TimePicker

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

TimePicker

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

Public methods

autofill

Added in API level 26
open fun autofill(value: AutofillValue!): Unit
Parameters
value AutofillValue!: value to be autofilled.

dispatchProvideAutofillStructure

Added in API level 26
open fun dispatchProvideAutofillStructure(
    structure: ViewStructure,
    flags: Int
): Unit
Parameters
structure ViewStructure: fill in with structured view data for autofill purposes. This value cannot be null.
flags Int: Value is either 0 or android.view.View#AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS

getAccessibilityClassName

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

getAutofillType

Added in API level 26
open fun getAutofillType(): Int

Describes the autofill type of this view, so an android.service.autofill.AutofillService can create the proper AutofillValue when autofilling the view.

By default returns AUTOFILL_TYPE_NONE, but views should override it to properly support the Autofill Framework.

Return
Int Value is android.view.View#AUTOFILL_TYPE_NONE, android.view.View#AUTOFILL_TYPE_TEXT, android.view.View#AUTOFILL_TYPE_TOGGLE, android.view.View#AUTOFILL_TYPE_LIST, or android.view.View#AUTOFILL_TYPE_DATE

getAutofillValue

Added in API level 26
open fun getAutofillValue(): AutofillValue?

getBaseline

Added in API level 1
open fun getBaseline(): Int
Return
Int the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported

getCurrentHour

Added in API level 1
Deprecated in API level 23
open fun getCurrentHour(): Int

Deprecated: Use getHour()

Return
Int the currently selected hour, in the range (0-23) This value cannot be null.

getCurrentMinute

Added in API level 1
Deprecated in API level 23
open fun getCurrentMinute(): Int

Deprecated: Use getMinute()

Return
Int the currently selected minute, in the range (0-59) This value cannot be null.

getHour

Added in API level 23
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

getMinute

Added in API level 23
open fun getMinute(): Int

Returns the currently selected minute.

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

See Also

is24HourView

Added in API level 1
open fun is24HourView(): Boolean
Return
Boolean true if this widget displays time in 24-hour mode, false otherwise}

isEnabled

Added in API level 1
open fun isEnabled(): Boolean
Return
Boolean True if this view is enabled, false otherwise.

setCurrentHour

Added in API level 1
Deprecated in API level 23
open fun setCurrentHour(currentHour: Int): Unit

Deprecated: Use setHour(int)

Sets the currently selected hour using 24-hour time.

Parameters
currentHour Int: the hour to set, in the range (0-23) This value cannot be null.

setCurrentMinute

Added in API level 1
Deprecated in API level 23
open fun setCurrentMinute(currentMinute: Int): Unit

Deprecated: Use setMinute(int)

Sets the currently selected minute.

Parameters
currentMinute Int: the minute to set, in the range (0-59) This value cannot be null.

setEnabled

Added in API level 1
open fun setEnabled(enabled: Boolean): Unit
Parameters
enabled Boolean: True if this view is enabled, false otherwise.

setHour

Added in API level 23
open fun setHour(hour: Int): Unit

Sets the currently selected hour using 24-hour time.

Parameters
hour Int: the hour to set, in the range (0-23) Value is between 0 and 23 inclusive

See Also

setIs24HourView

Added in API level 1
open fun setIs24HourView(is24HourView: Boolean): Unit

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

Parameters
is24HourView Boolean: true to display in 24-hour mode, false for 12-hour mode with AM/PM This value cannot be null.

See Also

setMinute

Added in API level 23
open fun setMinute(minute: Int): Unit

Sets the currently selected minute.

Parameters
minute Int: the minute to set, in the range (0-59) Value is between 0 and 59 inclusive

See Also

setOnTimeChangedListener

Added in API level 1
open fun setOnTimeChangedListener(onTimeChangedListener: TimePicker.OnTimeChangedListener!): Unit

Set the callback that indicates the time has been adjusted by the user.

Parameters
onTimeChangedListener TimePicker.OnTimeChangedListener!: the callback, should not be null.

validateInput

Added in API level 26
open fun validateInput(): Boolean

Validates whether current input by the user is a valid time based on the locale. TimePicker will show an error message to the user if the time is not valid.

Return
Boolean true if the input is valid, false otherwise

Protected methods

onRestoreInstanceState

Added in API level 1
protected open fun onRestoreInstanceState(state: Parcelable!): Unit
Parameters
state Parcelable!: The frozen state that had previously been returned by onSaveInstanceState.

onSaveInstanceState

Added in API level 1
protected open fun onSaveInstanceState(): Parcelable?
Return
Parcelable? Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save.