Register now for Android Dev Summit 2019!

DatePicker

public class DatePicker
extends Picker

java.lang.Object
   ↳ 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). R.attr.maxDate R.attr.minDate R.attr.datePickerFormat

Summary

Inherited constants

Inherited fields

Public constructors

DatePicker(Context context, AttributeSet attrs)
DatePicker(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

long getDate()

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

String getDatePickerFormat()

Get format of showing dates.

long getMaxDate()

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

long getMinDate()

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

final void onColumnValueChanged(int column, int newVal)

Classes extending Picker can override this function to supply the behavior when a list has been scrolled.

void setDate(long timeInMilliseconds)

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

void setDate(int year, int month, int dayOfMonth, boolean animation)

Update the current date.

void setDatePickerFormat(String datePickerFormat)

Changes format of showing dates.

void setMaxDate(long maxDate)

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

void setMinDate(long minDate)

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

Inherited methods

Public constructors

DatePicker

public DatePicker (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

DatePicker

public DatePicker (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

getDate

public long getDate ()

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

Returns
long Current date values.

getDatePickerFormat

public String getDatePickerFormat ()

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

Returns
String Format of showing dates.

getMaxDate

public long getMaxDate ()

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.

Returns
long The maximal supported date.

getMinDate

public long getMinDate ()

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.

Returns
long The minimal supported date.

onColumnValueChanged

public final void onColumnValueChanged (int column, 
                int newVal)

Classes extending Picker can override this function to supply the behavior when a list has been scrolled. Subclass may call setColumnValue(int, int, boolean) and or setColumnAt(int, PickerColumn). Subclass should not directly call PickerColumn.setCurrentValue(int) which does not update internal state or notify listeners.

Parameters
column int: index of which column was changed.

newVal int: A new value desired to be set on the column.

setDate

public void setDate (long timeInMilliseconds)

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

public void setDate (int year, 
                int month, 
                int dayOfMonth, 
                boolean animation)

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 boolean: True to run animation to scroll the column.

setDatePickerFormat

public void setDatePickerFormat (String datePickerFormat)

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

Parameters
datePickerFormat String: Format of showing dates.

setMaxDate

public void setMaxDate (long maxDate)

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

public void setMinDate (long minDate)

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.