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

Automatically fills the content of this view with the value.

open Unit

Dispatches creation of a ViewStructures for autofill purposes down the hierarchy, when an Assist structure is being created as part of an autofill request.

open CharSequence!

Return the class name of this object to be used for accessibility purposes.

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?

Gets the View's current autofill value.

open Int

Return the offset of the widget's text baseline from the widget's top boundary.

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

Returns the enabled status for this view.

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)

Set the enabled state of this view.

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

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState.

open Parcelable?

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state.

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 21
TimePicker(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

autofill

Added in API level 26
open fun autofill(value: AutofillValue!): Unit

Automatically fills the content of this view with the value.

Views support the Autofill Framework mainly by:

  • Providing the metadata defining what the view means and how it can be autofilled.
  • Implementing the methods that autofill the view.

onProvideAutofillStructure(android.view.ViewStructure,int) is responsible for the former, this method is responsible for latter.

This method does nothing by default, but when overridden it typically:

  1. Checks if the provided value matches the expected type (which is defined by getAutofillType()).
  2. Checks if the view is editable - if it isn't, it should return right away.
  3. Call the proper getter method on AutofillValue to fetch the actual value.
  4. Pass the actual value to the equivalent setter in the view.

For example, a text-field view could implement the method this way:

@Override
  public void autofill(AutofillValue value) {
    if (!value.isText() || !this.isEditable()) {
       return;
    }
    CharSequence text = value.getTextValue();
    if (text != null) {
      this.setText(text);
    }
  }
  

If the value is updated asynchronously, the next call to AutofillManager.notifyValueChanged(View) must happen after the value was changed to the autofilled value. If not, the view will not be considered autofilled.

Note: After this method is called, the value returned by getAutofillValue() must be equal to the value passed to it, otherwise the view will not be highlighted as autofilled.

Parameters
value AutofillValue!: value to be autofilled.

dispatchProvideAutofillStructure

Added in API level 26
open fun dispatchProvideAutofillStructure(
    structure: ViewStructure,
    flags: Int
): Unit

Dispatches creation of a ViewStructures for autofill purposes down the hierarchy, when an Assist structure is being created as part of an autofill request.

The default implementation does the following:

Typically, this method should only be overridden by subclasses that provide a view hierarchy (such as ViewGroup) - other classes should override onProvideAutofillStructure(android.view.ViewStructure,int) or onProvideAutofillVirtualStructure(android.view.ViewStructure,int) instead.

When overridden, it must:

  • Either call super.dispatchProvideAutofillStructure(structure, flags) or explicitly set the AutofillId in the structure (for example, by calling structure.setAutofillId(getAutofillId())).
  • Decide how to handle the AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS flag - when set, all views in the structure should be considered important for autofill, regardless of what isImportantForAutofill() returns. We encourage you to respect this flag to provide a better user experience - this flag is typically used when an user explicitly requested autofill. If the flag is not set, then only views marked as important for autofill should be included in the structure - skipping non-important views optimizes the overall autofill performance.

This implementation adds in all child views of the view group, in addition to calling the default View implementation.

Parameters
structure ViewStructure: fill in with structured view data for autofill purposes.
This value cannot be null.
flags Int: Value is either 0 or

getAccessibilityClassName

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

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

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 one of the following:

getAutofillValue

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

Gets the View's current autofill value.

By default returns null, but subclasses should override it and return an appropriate value to properly support the Autofill Framework.

getBaseline

Added in API level 1
open fun getBaseline(): Int

Return the offset of the widget's text baseline from the widget's top boundary. If this widget does not support baseline alignment, this method returns -1.

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

Returns the enabled status for this view. The interpretation of the enabled state varies by subclass.

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

Set the enabled state of this view. The interpretation of the enabled state varies by subclass.

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

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState. This function will never be called with a null state.
If you override this method you must call through to the superclass implementation.

Parameters
state Parcelable!: The frozen state that had previously been returned by onSaveInstanceState.

onSaveInstanceState

Added in API level 1
protected open fun onSaveInstanceState(): Parcelable?

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.

Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.
If you override this method you must call through to the superclass implementation.

Return
Parcelable? Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save.