Skip to content

Most visited

Recently visited

navigation

TimePickerDialog

public class TimePickerDialog
extends AlertDialog implements DialogInterface.OnClickListener, TimePicker.OnTimeChangedListener

java.lang.Object
   ↳ android.app.Dialog
     ↳ android.app.AlertDialog
       ↳ android.app.TimePickerDialog


A dialog that prompts the user for the time of day using a TimePicker.

See the Pickers guide.

Summary

Nested classes

interface TimePickerDialog.OnTimeSetListener

The callback interface used to indicate the user is done filling in the time (e.g. 

Inherited constants

From class android.app.AlertDialog
From interface android.content.DialogInterface

Public constructors

TimePickerDialog(Context context, TimePickerDialog.OnTimeSetListener listener, int hourOfDay, int minute, boolean is24HourView)

Creates a new time picker dialog.

TimePickerDialog(Context context, int themeResId, TimePickerDialog.OnTimeSetListener listener, int hourOfDay, int minute, boolean is24HourView)

Creates a new time picker dialog with the specified theme.

Public methods

void onClick(DialogInterface dialog, int which)

This method will be invoked when a button in the dialog is clicked.

void onRestoreInstanceState(Bundle savedInstanceState)

Restore the state of the dialog from a previously saved bundle.

Bundle onSaveInstanceState()

Saves the state of the dialog into a bundle.

void onTimeChanged(TimePicker view, int hourOfDay, int minute)
void show()

Start the dialog and display it on screen.

void updateTime(int hourOfDay, int minuteOfHour)

Sets the current time.

Inherited methods

From class android.app.AlertDialog
From class android.app.Dialog
From class java.lang.Object
From interface android.content.DialogInterface
From interface android.view.Window.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.View.OnCreateContextMenuListener
From interface android.content.DialogInterface.OnClickListener
From interface android.widget.TimePicker.OnTimeChangedListener

Public constructors

TimePickerDialog

added in API level 1
TimePickerDialog (Context context, 
                TimePickerDialog.OnTimeSetListener listener, 
                int hourOfDay, 
                int minute, 
                boolean is24HourView)

Creates a new time picker dialog.

Parameters
context Context: the parent context

listener TimePickerDialog.OnTimeSetListener: the listener to call when the time is set

hourOfDay int: the initial hour

minute int: the initial minute

is24HourView boolean: whether this is a 24 hour view or AM/PM

TimePickerDialog

added in API level 1
TimePickerDialog (Context context, 
                int themeResId, 
                TimePickerDialog.OnTimeSetListener listener, 
                int hourOfDay, 
                int minute, 
                boolean is24HourView)

Creates a new time picker dialog with the specified theme.

The theme is overlaid on top of the theme of the parent context. If themeResId is 0, the dialog will be inflated using the theme specified by the android:timePickerDialogTheme attribute on the parent context's theme.

Parameters
context Context: the parent context

themeResId int: the resource ID of the theme to apply to this dialog

listener TimePickerDialog.OnTimeSetListener: the listener to call when the time is set

hourOfDay int: the initial hour

minute int: the initial minute

is24HourView boolean: Whether this is a 24 hour view, or AM/PM.

Public methods

onClick

added in API level 1
void onClick (DialogInterface dialog, 
                int which)

This method will be invoked when a button in the dialog is clicked.

Parameters
dialog DialogInterface: the dialog that received the click

which int: the button that was clicked (ex. BUTTON_POSITIVE) or the position of the item clicked

onRestoreInstanceState

added in API level 1
void onRestoreInstanceState (Bundle savedInstanceState)

Restore the state of the dialog from a previously saved bundle. The default implementation restores the state of the dialog's view hierarchy that was saved in the default implementation of onSaveInstanceState(), so be sure to call through to super when overriding unless you want to do all restoring of state yourself.

Parameters
savedInstanceState Bundle: The state of the dialog previously saved by onSaveInstanceState().

onSaveInstanceState

added in API level 1
Bundle onSaveInstanceState ()

Saves the state of the dialog into a bundle. The default implementation saves the state of its view hierarchy, so you'll likely want to call through to super if you override this to save additional state.

Returns
Bundle A bundle with the state of the dialog.

onTimeChanged

added in API level 1
void onTimeChanged (TimePicker view, 
                int hourOfDay, 
                int minute)

Parameters
view TimePicker

hourOfDay int

minute int

show

added in API level 1
void show ()

Start the dialog and display it on screen. The window is placed in the application layer and opaque. Note that you should not override this method to do initialization when the dialog is shown, instead implement that in onStart().

updateTime

added in API level 1
void updateTime (int hourOfDay, 
                int minuteOfHour)

Sets the current time.

Parameters
hourOfDay int: The current hour within the day.

minuteOfHour int: The current minute within the hour.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

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.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)