The Android Developer Challenge is back! Submit your idea before December 2.

MaterialDatePicker

public final class MaterialDatePicker
extends DialogFragment

java.lang.Object
   ↳ androidx.fragment.app.Fragment
     ↳ androidx.fragment.app.DialogFragment
       ↳ com.google.android.material.datepicker.MaterialDatePicker<S>


A Dialog with a header, MaterialCalendar, and set of actions.

Summary

Nested classes

class MaterialDatePicker.Builder<S>

Used to create MaterialDatePicker instances with default and overridden settings  

Inherited constants

From class androidx.fragment.app.DialogFragment

Public constructors

MaterialDatePicker()

Public methods

boolean addOnCancelListener(DialogInterface.OnCancelListener onCancelListener)

The supplied listener is called when the user cancels the picker via back button or a touch outside the view.

boolean addOnDismissListener(DialogInterface.OnDismissListener onDismissListener)

The supplied listener is called whenever the DialogFragment is dismissed, no matter how it is dismissed.

boolean addOnNegativeButtonClickListener(View.OnClickListener onNegativeButtonClickListener)

The supplied listener is called when the user clicks the cancel button.

boolean addOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener<? super S> onPositiveButtonClickListener)

The supplied listener is called when the user confirms a valid selection.

void clearOnCancelListeners()

Removes all listeners added via addOnCancelListener(DialogInterface.OnCancelListener).

void clearOnDismissListeners()

Removes all listeners added via addOnDismissListener(DialogInterface.OnDismissListener).

void clearOnNegativeButtonClickListeners()

Removes all listeners added via addOnNegativeButtonClickListener(View.OnClickListener).

void clearOnPositiveButtonClickListeners()

Removes all listeners added via addOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener).

String getHeaderText()

Returns the text to display at the top of the DialogFragment

The text is updated when the Dialog launches and on user clicks.

S getSelection()

Returns an S instance representing the selection or null if the user has not confirmed a selection.

void onCancel(DialogInterface dialogInterface)
void onCreate(Bundle bundle)
Dialog onCreateDialog(Bundle bundle)
View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle)
void onDismiss(DialogInterface dialogInterface)
void onSaveInstanceState(Bundle bundle)
void onStart()
void onStop()
boolean removeOnCancelListener(DialogInterface.OnCancelListener onCancelListener)

Removes a listener previously added via addOnCancelListener(DialogInterface.OnCancelListener).

boolean removeOnDismissListener(DialogInterface.OnDismissListener onDismissListener)

Removes a listener previously added via addOnDismissListener(DialogInterface.OnDismissListener).

boolean removeOnNegativeButtonClickListener(View.OnClickListener onNegativeButtonClickListener)

Removes a listener previously added via addOnNegativeButtonClickListener(View.OnClickListener).

boolean removeOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener<? super S> onPositiveButtonClickListener)

Removes a listener previously added via addOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener).

static long todayInUtcMilliseconds()

Returns a value of UTC milliseconds representing today for the device's current timezone.

Inherited methods

From class androidx.fragment.app.DialogFragment
From class androidx.fragment.app.Fragment
From class java.lang.Object
From interface android.content.DialogInterface.OnCancelListener
From interface android.content.DialogInterface.OnDismissListener
From interface android.content.ComponentCallbacks
From interface android.view.View.OnCreateContextMenuListener
From interface androidx.lifecycle.LifecycleOwner
From interface androidx.lifecycle.ViewModelStoreOwner
From interface androidx.savedstate.SavedStateRegistryOwner

Public constructors

MaterialDatePicker

MaterialDatePicker ()

Public methods

addOnCancelListener

boolean addOnCancelListener (DialogInterface.OnCancelListener onCancelListener)

The supplied listener is called when the user cancels the picker via back button or a touch outside the view. It is not called when the user clicks the cancel button. To add a listener for use when the user clicks the cancel button, use addOnNegativeButtonClickListener(View.OnClickListener).

Parameters
onCancelListener DialogInterface.OnCancelListener

Returns
boolean

addOnDismissListener

boolean addOnDismissListener (DialogInterface.OnDismissListener onDismissListener)

The supplied listener is called whenever the DialogFragment is dismissed, no matter how it is dismissed.

Parameters
onDismissListener DialogInterface.OnDismissListener

Returns
boolean

addOnNegativeButtonClickListener

boolean addOnNegativeButtonClickListener (View.OnClickListener onNegativeButtonClickListener)

The supplied listener is called when the user clicks the cancel button.

Parameters
onNegativeButtonClickListener View.OnClickListener

Returns
boolean

addOnPositiveButtonClickListener

boolean addOnPositiveButtonClickListener (MaterialPickerOnPositiveButtonClickListener<? super S> onPositiveButtonClickListener)

The supplied listener is called when the user confirms a valid selection.

Parameters
onPositiveButtonClickListener MaterialPickerOnPositiveButtonClickListener

Returns
boolean

clearOnCancelListeners

void clearOnCancelListeners ()

Removes all listeners added via addOnCancelListener(DialogInterface.OnCancelListener).

clearOnDismissListeners

void clearOnDismissListeners ()

Removes all listeners added via addOnDismissListener(DialogInterface.OnDismissListener).

clearOnNegativeButtonClickListeners

void clearOnNegativeButtonClickListeners ()

Removes all listeners added via addOnNegativeButtonClickListener(View.OnClickListener).

clearOnPositiveButtonClickListeners

void clearOnPositiveButtonClickListeners ()

Removes all listeners added via addOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener).

getHeaderText

String getHeaderText ()

Returns the text to display at the top of the DialogFragment

The text is updated when the Dialog launches and on user clicks.

Returns
String

getSelection

S getSelection ()

Returns an S instance representing the selection or null if the user has not confirmed a selection.

Returns
S

onCancel

void onCancel (DialogInterface dialogInterface)

Parameters
dialogInterface DialogInterface

onCreate

void onCreate (Bundle bundle)

Parameters
bundle Bundle

onCreateDialog

Dialog onCreateDialog (Bundle bundle)

Parameters
bundle Bundle

Returns
Dialog

onCreateView

View onCreateView (LayoutInflater layoutInflater, 
                ViewGroup viewGroup, 
                Bundle bundle)

Parameters
layoutInflater LayoutInflater

viewGroup ViewGroup

bundle Bundle

Returns
View

onDismiss

void onDismiss (DialogInterface dialogInterface)

Parameters
dialogInterface DialogInterface

onSaveInstanceState

void onSaveInstanceState (Bundle bundle)

Parameters
bundle Bundle

onStart

void onStart ()

onStop

void onStop ()

removeOnCancelListener

boolean removeOnCancelListener (DialogInterface.OnCancelListener onCancelListener)

Removes a listener previously added via addOnCancelListener(DialogInterface.OnCancelListener).

Parameters
onCancelListener DialogInterface.OnCancelListener

Returns
boolean

removeOnDismissListener

boolean removeOnDismissListener (DialogInterface.OnDismissListener onDismissListener)

Removes a listener previously added via addOnDismissListener(DialogInterface.OnDismissListener).

Parameters
onDismissListener DialogInterface.OnDismissListener

Returns
boolean

removeOnNegativeButtonClickListener

boolean removeOnNegativeButtonClickListener (View.OnClickListener onNegativeButtonClickListener)

Removes a listener previously added via addOnNegativeButtonClickListener(View.OnClickListener).

Parameters
onNegativeButtonClickListener View.OnClickListener

Returns
boolean

removeOnPositiveButtonClickListener

boolean removeOnPositiveButtonClickListener (MaterialPickerOnPositiveButtonClickListener<? super S> onPositiveButtonClickListener)

Removes a listener previously added via addOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener).

Parameters
onPositiveButtonClickListener MaterialPickerOnPositiveButtonClickListener

Returns
boolean

todayInUtcMilliseconds

long todayInUtcMilliseconds ()

Returns a value of UTC milliseconds representing today for the device's current timezone.

Returns
long