Android APIs
public class

TimePicker

extends FrameLayout
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.widget.TimePicker

Class Overview

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

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

Summary

Nested Classes
interface TimePicker.OnTimeChangedListener The callback interface used to indicate the time has been adjusted. 
XML Attributes
Attribute Name Related Method Description
android:timePickerMode Defines the look of the widget. 
[Expand]
Inherited XML Attributes
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
TimePicker(Context context)
TimePicker(Context context, AttributeSet attrs)
TimePicker(Context context, AttributeSet attrs, int defStyleAttr)
TimePicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Public Methods
CharSequence getAccessibilityClassName()
Return the class name of this object to be used for accessibility purposes.
int getBaseline()

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

Integer getCurrentHour()
This method was deprecated in API level 23. Use getHour()
Integer getCurrentMinute()
This method was deprecated in API level 23. Use getMinute()
int getHour()
Returns the currently selected hour using 24-hour time.
int getMinute()
Returns the currently selected minute.
boolean is24HourView()
boolean isEnabled()
Returns the enabled status for this view.
void setCurrentHour(Integer currentHour)
This method was deprecated in API level 23. Use setHour(int)
void setCurrentMinute(Integer currentMinute)
This method was deprecated in API level 23. Use setMinute(int)
void setEnabled(boolean enabled)
Set the enabled state of this view.
void setHour(int hour)
Sets the currently selected hour using 24-hour time.
void setIs24HourView(Boolean is24HourView)
Sets whether this widget displays time in 24-hour mode or 12-hour mode with an AM/PM picker.
void setMinute(int minute)
Sets the currently selected minute..
void setOnTimeChangedListener(TimePicker.OnTimeChangedListener onTimeChangedListener)
Set the callback that indicates the time has been adjusted by the user.
Protected Methods
void onConfigurationChanged(Configuration newConfig)
Called when the current configuration of the resources being used by the application have changed.
void onRestoreInstanceState(Parcelable state)
Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().
Parcelable onSaveInstanceState()
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.
[Expand]
Inherited Methods
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

XML Attributes

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.

ConstantValueDescription
spinner1 Time picker with spinner controls to select the time.
clock2 Time picker with clock face to select the time.

This corresponds to the global attribute resource symbol timePickerMode.

Related Methods

Public Constructors

public TimePicker (Context context)

Added in API level 1

Parameters
context Context

public TimePicker (Context context, AttributeSet attrs)

Added in API level 1

Parameters
context Context
attrs AttributeSet

public TimePicker (Context context, AttributeSet attrs, int defStyleAttr)

Added in API level 1

Parameters
context Context
attrs AttributeSet
defStyleAttr int

public TimePicker (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Added in API level 21

Parameters
context Context
attrs AttributeSet
defStyleAttr int
defStyleRes int

Public Methods

public CharSequence getAccessibilityClassName ()

Added in API level 23

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.

Returns
CharSequence

public int getBaseline ()

Added in API level 1

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.

Returns
int the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported

public Integer getCurrentHour ()

Added in API level 1

This method was deprecated in API level 23.
Use getHour()

Returns
Integer the current hour in the range (0-23)

public Integer getCurrentMinute ()

Added in API level 1

This method was deprecated in API level 23.
Use getMinute()

Returns
Integer the current minute

public int getHour ()

Added in API level 23

Returns the currently selected hour using 24-hour time.

Returns
int the currently selected hour, in the range (0-23)

See also:

public int getMinute ()

Added in API level 23

Returns the currently selected minute.

Returns
int the currently selected minute, in the range (0-59)

See also:

public boolean is24HourView ()

Added in API level 1

Returns
boolean true if this widget displays time in 24-hour mode, false otherwise}

public boolean isEnabled ()

Added in API level 1

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

Returns
boolean True if this view is enabled, false otherwise.

public void setCurrentHour (Integer currentHour)

Added in API level 1

This method was deprecated in API level 23.
Use setHour(int)

Sets the current hour.

Parameters
currentHour Integer

public void setCurrentMinute (Integer currentMinute)

Added in API level 1

This method was deprecated in API level 23.
Use setMinute(int)

Set the current minute (0-59).

Parameters
currentMinute Integer

public void setEnabled (boolean enabled)

Added in API level 1

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.

public void setHour (int hour)

Added in API level 23

Sets the currently selected hour using 24-hour time.

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

See also:

public void setIs24HourView (Boolean is24HourView)

Added in API level 1

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

See also:

public void setMinute (int minute)

Added in API level 23

Sets the currently selected minute..

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

See also:

public void setOnTimeChangedListener (TimePicker.OnTimeChangedListener onTimeChangedListener)

Added in API level 1

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

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

Protected Methods

protected void onConfigurationChanged (Configuration newConfig)

Added in API level 8

Called when the current configuration of the resources being used by the application have changed. You can use this to decide when to reload resources that can changed based on orientation and other configuration characteristics. You only need to use this if you are not relying on the normal Activity mechanism of recreating the activity instance upon a configuration change.

Parameters
newConfig Configuration: The new resource configuration.

protected void onRestoreInstanceState (Parcelable state)

Added in API level 1

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.

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

protected Parcelable onSaveInstanceState ()

Added in API level 1

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.

Returns
Parcelable Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save. The default implementation returns null.