Skip to content

Most visited

Recently visited

navigation
Added in API level 1

TimePicker

public class TimePicker
extends FrameLayout

java.lang.Object
   ↳ 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 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

android:timePickerMode Defines the look of the widget. 

Inherited XML attributes

From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View

Inherited constants

From class android.view.ViewGroup
From class android.view.View

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.

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.

Public constructors

TimePicker

Added in API level 1
TimePicker (Context context)

Parameters
context Context

TimePicker

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

Parameters
context Context
attrs AttributeSet

TimePicker

Added in API level 1
TimePicker (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context
attrs AttributeSet
defStyleAttr int

TimePicker

Added in API level 21
TimePicker (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context
attrs AttributeSet
defStyleAttr int
defStyleRes int

Public methods

getAccessibilityClassName

Added in API level 23
CharSequence getAccessibilityClassName ()

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

getBaseline

Added in API level 1
int getBaseline ()

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

getCurrentHour

Added in API level 1
Integer getCurrentHour ()

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

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

getCurrentMinute

Added in API level 1
Integer getCurrentMinute ()

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

Returns
Integer the current minute

getHour

Added in API level 23
int getHour ()

Returns the currently selected hour using 24-hour time.

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

See also:

getMinute

Added in API level 23
int getMinute ()

Returns the currently selected minute.

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

See also:

is24HourView

Added in API level 1
boolean is24HourView ()

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

See also:

isEnabled

Added in API level 1
boolean isEnabled ()

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.

setCurrentHour

Added in API level 1
void setCurrentHour (Integer currentHour)

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

Sets the current hour.

Parameters
currentHour Integer

setCurrentMinute

Added in API level 1
void setCurrentMinute (Integer currentMinute)

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

Set the current minute (0-59).

Parameters
currentMinute Integer

setEnabled

Added in API level 1
void setEnabled (boolean enabled)

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
void setHour (int hour)

Sets the currently selected hour using 24-hour time.

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

See also:

setIs24HourView

Added in API level 1
void setIs24HourView (Boolean is24HourView)

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:

setMinute

Added in API level 23
void setMinute (int minute)

Sets the currently selected minute..

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

See also:

setOnTimeChangedListener

Added in API level 1
void setOnTimeChangedListener (TimePicker.OnTimeChangedListener onTimeChangedListener)

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

onConfigurationChanged

Added in API level 8
void onConfigurationChanged (Configuration newConfig)

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.

onRestoreInstanceState

Added in API level 1
void onRestoreInstanceState (Parcelable state)

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().

onSaveInstanceState

Added in API level 1
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. 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.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.