Skip to content

Most visited

Recently visited

navigation
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 callback used to indicate the user is done filling in the date. 

Inherited constants

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

Public constructors

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

Public methods

DatePicker getDatePicker()

Gets 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 day)

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 updateDate(int year, int monthOfYear, 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 1
DatePickerDialog (Context context, 
                DatePickerDialog.OnDateSetListener callBack, 
                int year, 
                int monthOfYear, 
                int dayOfMonth)

Parameters
context Context: The context the dialog is to run in.
callBack DatePickerDialog.OnDateSetListener: How the parent is notified that the date is set.
year int: The initial year of the dialog.
monthOfYear int: The initial month of the dialog.
dayOfMonth int: The initial day of the dialog.

DatePickerDialog

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

Parameters
context Context: The context the dialog is to run in.
theme int: the theme to apply to this dialog
listener DatePickerDialog.OnDateSetListener: How the parent is notified that the date is set.
year int: The initial year of the dialog.
monthOfYear int: The initial month of the dialog.
dayOfMonth int: The initial day of the dialog.

Public methods

getDatePicker

Added in API level 11
DatePicker getDatePicker ()

Gets the DatePicker contained in this dialog.

Returns
DatePicker The calendar view.

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 day)

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.
day 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.

updateDate

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

Sets the current date.

Parameters
year int: The date year.
monthOfYear int: The date month.
dayOfMonth int: The date day of month.
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.