Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

DatePicker

open class DatePicker : Picker
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.FrameLayout
   ↳ androidx.leanback.widget.picker.Picker
   ↳ androidx.leanback.widget.picker.DatePicker

DatePicker is a directly subclass of Picker. This class is a widget for selecting a date. The date can be selected by a year, month, and day Columns. The "minDate" and "maxDate" from which dates to be selected can be customized. The columns can be customized by attribute "datePickerFormat" or setDatePickerFormat(String). android.R.attr#maxDate android.R.attr#minDate R.attr#datePickerFormat

Summary

Public constructors

<init>(context: Context!, attrs: AttributeSet!)

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Public methods

open Long

Gets current date value in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

open String!

Get format of showing dates.

open Long

Gets the maximal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

open Long

Gets the minimal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

Unit
onColumnValueChanged(column: Int, newVal: Int)

open Unit
setDate(timeInMilliseconds: Long)

Update the current date in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

open Unit
setDate(year: Int, month: Int, dayOfMonth: Int, animation: Boolean)

Update the current date.

open Unit
setDatePickerFormat(datePickerFormat: String!)

Changes format of showing dates.

open Unit
setMaxDate(maxDate: Long)

Sets the maximal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

open Unit
setMinDate(minDate: Long)

Sets the minimal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

Inherited functions

Public constructors

<init>

DatePicker(context: Context!, attrs: AttributeSet!)

<init>

DatePicker(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Public methods

getDate

open fun getDate(): Long

Gets current date value in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

Return
Long: Current date values.

getDatePickerFormat

open fun getDatePickerFormat(): String!

Get format of showing dates. For example "YMD". Default value is from android.text.format.DateFormat#getDateFormatOrder(Context).

Return
String!: Format of showing dates.

getMaxDate

open fun getMaxDate(): Long

Gets the maximal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

Note: The default maximal date is 12/31/2100.

Return
Long: The maximal supported date.

getMinDate

open fun getMinDate(): Long

Gets the minimal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

Note: The default minimal date is 01/01/1900.

Return
Long: The minimal supported date.

onColumnValueChanged

fun onColumnValueChanged(column: Int, newVal: Int): Unit

setDate

open fun setDate(timeInMilliseconds: Long): Unit

Update the current date in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

Parameters
timeInMilliseconds Long: current date value in milliseconds.

setDate

open fun setDate(year: Int, month: Int, dayOfMonth: Int, animation: Boolean): Unit

Update the current date.

Parameters
year Int: The year.
month Int: The month which is starting from zero.
dayOfMonth Int: The day of the month.
animation Int: True to run animation to scroll the column.

setDatePickerFormat

open fun setDatePickerFormat(datePickerFormat: String!): Unit

Changes format of showing dates. For example "YMD".

Parameters
datePickerFormat String!: Format of showing dates.

setMaxDate

open fun setMaxDate(maxDate: Long): Unit

Sets the maximal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

Parameters
maxDate Long: The maximal supported date.

setMinDate

open fun setMinDate(minDate: Long): Unit

Sets the minimal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

Parameters
minDate Long: The minimal supported date.