Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
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 view for selecting the time of day, in either 24 hour or AM/PM mode. The hour, each minute digit, and AM/PM (if applicable) can be conrolled by vertical spinners. The hour can be entered by keyboard input. Entering in two digit hours can be accomplished by hitting two digits within a timeout of about a second (e.g. '1' then '2' to select 12). The minutes can be entered by entering single digits. Under AM/PM mode, the user can hit 'a', 'A", 'p' or 'P' to pick. For a dialog using this view, see TimePickerDialog .

See the Pickers guide.

Summary

Nested Classes
interface TimePicker.OnTimeChangedListener The callback interface used to indicate the time has been adjusted. 
[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 defStyle)
Public Methods
boolean dispatchPopulateAccessibilityEvent ( AccessibilityEvent event)
Dispatches an AccessibilityEvent to the View first and then to its children for adding their text content to the event.
int getBaseline ()

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

Integer getCurrentHour ()
Integer getCurrentMinute ()
boolean is24HourView ()
boolean isEnabled ()
Returns the enabled status for this view.
void onInitializeAccessibilityEvent ( AccessibilityEvent event)
Initializes an AccessibilityEvent with information about this View which is the event source.
void onInitializeAccessibilityNodeInfo ( AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about this view.
void onPopulateAccessibilityEvent ( AccessibilityEvent event)
Called from dispatchPopulateAccessibilityEvent(AccessibilityEvent) giving a chance to this View to populate the accessibility event with its text content.
void setCurrentHour ( Integer currentHour)
Set the current hour.
void setCurrentMinute ( Integer currentMinute)
Set the current minute (0-59).
void setEnabled (boolean enabled)
Set the enabled state of this view.
void setIs24HourView ( Boolean is24HourView)
Set whether in 24 hour or AM/PM mode.
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.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

Public Constructors

public TimePicker ( Context context)

Added in API level 1

public TimePicker ( Context context, AttributeSet attrs)

Added in API level 1

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

Added in API level 1

Public Methods

public boolean dispatchPopulateAccessibilityEvent ( AccessibilityEvent event)

Added in API level 4

Dispatches an AccessibilityEvent to the View first and then to its children for adding their text content to the event. Note that the event text is populated in a separate dispatch path since we add to the event not only the text of the source but also the text of all its descendants. A typical implementation will call onPopulateAccessibilityEvent(AccessibilityEvent) on the this view and then call the dispatchPopulateAccessibilityEvent(AccessibilityEvent) on each child. Override this method if custom population of the event text content is required.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its dispatchPopulateAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Accessibility events of certain types are not dispatched for populating the event text via this method. For details refer to AccessibilityEvent .

Parameters
event The event.
Returns
  • True if the event population was completed.

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
  • 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

Returns
  • The current hour in the range (0-23).

public Integer getCurrentMinute ()

Added in API level 1

Returns
  • The current minute.

public boolean is24HourView ()

Added in API level 1

Returns
  • true if this is in 24 hour view else false.

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
  • True if this view is enabled, false otherwise.

public void onInitializeAccessibilityEvent ( AccessibilityEvent event)

Initializes an AccessibilityEvent with information about this View which is the event source. In other words, the source of an accessibility event is the view whose state change triggered firing the event.

Example: Setting the password property of an event in addition to properties set by the super implementation:

          public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setPassword(true);
 }
         

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event The event to initialize.

public void onInitializeAccessibilityNodeInfo ( AccessibilityNodeInfo info)

Parameters
info The instance to initialize.

public void onPopulateAccessibilityEvent ( AccessibilityEvent event)

Called from dispatchPopulateAccessibilityEvent(AccessibilityEvent) giving a chance to this View to populate the accessibility event with its text content. While this method is free to modify event attributes other than text content, doing so should normally be performed in onInitializeAccessibilityEvent(AccessibilityEvent) .

Example: Adding formatted date string to an accessibility event in addition to the text added by the super implementation:

          public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
     super.onPopulateAccessibilityEvent(event);
     final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY;
     String selectedDateUtterance = DateUtils.formatDateTime(mContext,
         mCurrentDate.getTimeInMillis(), flags);
     event.getText().add(selectedDateUtterance);
 }
         

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onPopulateAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event The accessibility event which to populate.

public void setCurrentHour ( Integer currentHour)

Added in API level 1

Set the current hour.

public void setCurrentMinute ( Integer currentMinute)

Added in API level 1

Set the current minute (0-59).

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 True if this view is enabled, false otherwise.

public void setIs24HourView ( Boolean is24HourView)

Added in API level 1

Set whether in 24 hour or AM/PM mode.

Parameters
is24HourView True = 24 hour mode. False = AM/PM.

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 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 characterstics. 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 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 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
  • 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.