Most visited

Recently visited

Added in API level 1

DatePickerDialog

public class DatePickerDialog
extends AlertDialog implements DialogInterface.OnClickListener, DatePicker.OnDateChangedListener

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


A simple dialog containing an DatePicker.

See the Pickers guide.

Summary

Nested classes

interface DatePickerDialog.OnDateSetListener

The listener used to indicate the user has finished selecting a date. 

Inherited constants

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

Public constructors

DatePickerDialog(Context context)

Creates a new date picker dialog for the current date using the parent context's default date picker dialog theme.

DatePickerDialog(Context context, int themeResId)

Creates a new date picker dialog for the current date.

DatePickerDialog(Context context, DatePickerDialog.OnDateSetListener listener, int year, int month, int dayOfMonth)

Creates a new date picker dialog for the specified date using the parent context's default date picker dialog theme.

DatePickerDialog(Context context, int themeResId, DatePickerDialog.OnDateSetListener listener, int year, int monthOfYear, int dayOfMonth)

Creates a new date picker dialog for the specified date.

Public methods

DatePicker getDatePicker()

Returns the DatePicker contained in this dialog.

void onClick(DialogInterface dialog, int which)

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

void onDateChanged(DatePicker view, int year, int month, int dayOfMonth)

Called upon a date change.

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 setOnDateSetListener(DatePickerDialog.OnDateSetListener listener)

Sets the listener to call when the user sets the date.

void updateDate(int year, int month, int dayOfMonth)

Sets the current date.

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.DatePicker.OnDateChangedListener

Public constructors

DatePickerDialog

Added in API level 24
DatePickerDialog (Context context)

Creates a new date picker dialog for the current date using the parent context's default date picker dialog theme.

Parameters
context Context: the parent context

DatePickerDialog

Added in API level 24
DatePickerDialog (Context context, 
                int themeResId)

Creates a new date picker dialog for the current date.

Parameters
context Context: the parent context
themeResId int: the resource ID of the theme against which to inflate this dialog, or 0 to use the parent context's default alert dialog theme

DatePickerDialog

Added in API level 1
DatePickerDialog (Context context, 
                DatePickerDialog.OnDateSetListener listener, 
                int year, 
                int month, 
                int dayOfMonth)

Creates a new date picker dialog for the specified date using the parent context's default date picker dialog theme.

Parameters
context Context: the parent context
listener DatePickerDialog.OnDateSetListener: the listener to call when the user sets the date
year int: the initially selected year
month int: the initially selected month (0-11 for compatibility with MONTH)
dayOfMonth int: the initially selected day of month (1-31, depending on month)

DatePickerDialog

Added in API level 1
DatePickerDialog (Context context, 
                int themeResId, 
                DatePickerDialog.OnDateSetListener listener, 
                int year, 
                int monthOfYear, 
                int dayOfMonth)

Creates a new date picker dialog for the specified date.

Parameters
context Context: the parent context
themeResId int: the resource ID of the theme against which to inflate this dialog, or 0 to use the parent context's default alert dialog theme
listener DatePickerDialog.OnDateSetListener: the listener to call when the user sets the date
year int: the initially selected year
monthOfYear int: the initially selected month of the year (0-11 for compatibility with MONTH)
dayOfMonth int: the initially selected day of month (1-31, depending on month)

Public methods

getDatePicker

Added in API level 11
DatePicker getDatePicker ()

Returns the DatePicker contained in this dialog.

Returns
DatePicker the date picker

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 (e.g. BUTTON1) or the position of the item clicked.

onDateChanged

Added in API level 1
void onDateChanged (DatePicker view, 
                int year, 
                int month, 
                int dayOfMonth)

Called upon a date change.

Parameters
view DatePicker: The view associated with this listener.
year int: The year that was set.
month int: The month that was set (0-11) for compatibility with Calendar.
dayOfMonth int: The day of the month that was set.

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.

setOnDateSetListener

Added in API level 24
void setOnDateSetListener (DatePickerDialog.OnDateSetListener listener)

Sets the listener to call when the user sets the date.

Parameters
listener DatePickerDialog.OnDateSetListener: the listener to call when the user sets the date

updateDate

Added in API level 1
void updateDate (int year, 
                int month, 
                int dayOfMonth)

Sets the current date.

Parameters
year int: the year
month int: the month (0-11 for compatibility with MONTH)
dayOfMonth int: the day of month (1-31, depending on month)

Hooray!