Added in API level 1

DatePickerDialog


open class DatePickerDialog : AlertDialog, DatePicker.OnDateChangedListener, DialogInterface.OnClickListener
kotlin.Any
   ↳ android.app.Dialog
   ↳ android.app.AlertDialog
   ↳ android.app.DatePickerDialog

A simple dialog containing an android.widget.DatePicker.

See the Pickers guide.

Summary

Nested classes
abstract

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

Inherited constants
Public constructors

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

DatePickerDialog(context: Context, listener: DatePickerDialog.OnDateSetListener?, year: Int, month: Int, dayOfMonth: Int)

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

DatePickerDialog(context: Context, themeResId: Int)

Creates a new date picker dialog for the current date.

DatePickerDialog(context: Context, themeResId: Int, listener: DatePickerDialog.OnDateSetListener?, year: Int, monthOfYear: Int, dayOfMonth: Int)

Creates a new date picker dialog for the specified date.

Public methods
open DatePicker

Returns the DatePicker contained in this dialog.

open Unit
onClick(dialog: DialogInterface, which: Int)

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

open Unit
onDateChanged(view: DatePicker, year: Int, month: Int, dayOfMonth: Int)

Called upon a date change.

open Unit
onRestoreInstanceState(savedInstanceState: Bundle)

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

open Bundle

Saves the state of the dialog into a bundle.

open Unit

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

open Unit
updateDate(year: Int, month: Int, dayOfMonth: Int)

Sets the current date.

Inherited functions

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.
This value cannot be null.

DatePickerDialog

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

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

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

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

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

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

Added in API level 11
open fun getDatePicker(): DatePicker

Returns the DatePicker contained in this dialog.

Return
DatePicker the date picker.
This value cannot be null.

onClick

Added in API level 1
open fun onClick(
    dialog: DialogInterface,
    which: Int
): Unit

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

Added in API level 1
open fun onDateChanged(
    view: DatePicker,
    year: Int,
    month: Int,
    dayOfMonth: Int
): Unit

Called upon a date change.

Parameters
view DatePicker: This value cannot be null.
year Int: The year that was set.
monthOfYear The month that was set (0-11) for compatibility with java.util.Calendar.
dayOfMonth Int: The day of the month that was set.

onRestoreInstanceState

Added in API level 1
open fun onRestoreInstanceState(savedInstanceState: Bundle): Unit

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

Added in API level 1
open fun onSaveInstanceState(): Bundle

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.

Return
Bundle A bundle with the state of the dialog.
This value cannot be null.

setOnDateSetListener

Added in API level 24
open fun setOnDateSetListener(listener: DatePickerDialog.OnDateSetListener?): Unit

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

Added in API level 1
open fun updateDate(
    year: Int,
    month: Int,
    dayOfMonth: Int
): Unit

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)