DatePickerDialog
public class DatePickerDialog
extends AlertDialog implements DatePicker.OnDateChangedListener, DialogInterface.OnClickListener
| 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 |
|---|
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, 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) Creates a new date picker dialog for the current date. | |
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 |
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 | |
|---|---|
Public constructors
DatePickerDialog
public 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 This value cannot be null. |
DatePickerDialog
public 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 This value cannot be null. |
listener | DatePickerDialog.OnDateSetListener: the listener to call when the user sets the date This value may be null. |
year | int: the initially selected year |
month | int: the initially selected month (0-11 for compatibility with Calendar.MONTH) |
dayOfMonth | int: the initially selected day of month (1-31, depending on month) |
DatePickerDialog
public DatePickerDialog (Context context, int themeResId)
Creates a new date picker dialog for the current date.
| Parameters | |
|---|---|
context | Context: the parent context This value cannot be null. |
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
public 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 This value cannot be null. |
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 This value may be null. |
year | int: the initially selected year |
monthOfYear | int: the initially selected month of the year (0-11 for compatibility with Calendar.MONTH) |
dayOfMonth | int: the initially selected day of month (1-31, depending on month) |
Public methods
getDatePicker
public DatePicker getDatePicker ()
Returns the DatePicker contained in this dialog.
| Returns | |
|---|---|
DatePicker | the date picker This value cannot be null. |
onClick
public void onClick (DialogInterface dialog, int which)
This method will be invoked when a button in the dialog is clicked.
| Parameters | |
|---|---|
dialog | DialogInterface: This value cannot be null. |
which | int: the button that was clicked (ex. DialogInterface.BUTTON_POSITIVE) or the position of the item clicked |
onDateChanged
public void onDateChanged (DatePicker view, int year, int month, int dayOfMonth)
Called upon a date change.
| Parameters | |
|---|---|
view | DatePicker: This value cannot be null. |
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
public 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(). This value cannot be null. |
onSaveInstanceState
public 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. This value cannot be null. |
setOnDateSetListener
public 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 This value may be null. |
updateDate
public 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 Calendar.MONTH) |
dayOfMonth | int: the day of month (1-31, depending on month) |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.