MaterialTimePicker

public final class MaterialTimePicker
extends DialogFragment

java.lang.Object
   ↳ androidx.fragment.app.Fragment
     ↳ androidx.fragment.app.DialogFragment
       ↳ com.google.android.material.timepicker.MaterialTimePicker


A Dialog with a clock display and a clock face to choose the time.

For more information, see the component developer guidance and design guidelines.

Summary

Nested classes

class MaterialTimePicker.Builder

Used to create MaterialTimePicker instances. 

Constants

int INPUT_MODE_CLOCK

int INPUT_MODE_KEYBOARD

Inherited constants

Public constructors

MaterialTimePicker()

Public methods

boolean addOnCancelListener(DialogInterface.OnCancelListener listener)

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

boolean addOnDismissListener(DialogInterface.OnDismissListener listener)

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

boolean addOnNegativeButtonClickListener(View.OnClickListener listener)

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

boolean addOnPositiveButtonClickListener(View.OnClickListener listener)

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

void clearOnCancelListeners()

Removes all listeners added via addOnCancelListener(OnCancelListener).

void clearOnDismissListeners()

Removes all listeners added via addOnDismissListener(OnDismissListener).

void clearOnNegativeButtonClickListeners()

Removes all listeners added via addOnNegativeButtonClickListener(OnClickListener).

void clearOnPositiveButtonClickListeners()

Removes all listeners added via addOnPositiveButtonClickListener(OnClickListener).

int getHour()

Returns the hour of day in the range [0, 23].

int getInputMode()
int getMinute()

Returns the minute in the range [0, 59].

void onCancel(DialogInterface dialogInterface)
void onCreate(Bundle bundle)
Dialog onCreateDialog(Bundle bundle)
View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle)
void onDestroyView()
void onDismiss(DialogInterface dialogInterface)
void onSaveInstanceState(Bundle bundle)
void onViewCreated(View view, Bundle bundle)
boolean removeOnCancelListener(DialogInterface.OnCancelListener listener)

Removes a listener previously added via addOnCancelListener(OnCancelListener).

boolean removeOnDismissListener(DialogInterface.OnDismissListener listener)

Removes a listener previously added via addOnDismissListener(OnDismissListener).

boolean removeOnNegativeButtonClickListener(View.OnClickListener listener)

Removes a listener previously added via addOnNegativeButtonClickListener(OnClickListener).

boolean removeOnPositiveButtonClickListener(View.OnClickListener listener)

Removes a listener previously added via addOnPositiveButtonClickListener(OnClickListener).

void setCancelable(boolean cancelable)
void setHour(int hour)

Sets the hour of day in the range [0, 23].

void setMinute(int minute)

Sets the minute in the range [0, 59].

Inherited methods

Constants

INPUT_MODE_CLOCK

public static final int INPUT_MODE_CLOCK

Constant Value: 0 (0x00000000)

INPUT_MODE_KEYBOARD

public static final int INPUT_MODE_KEYBOARD

Constant Value: 1 (0x00000001)

Public constructors

MaterialTimePicker

public MaterialTimePicker ()

Public methods

addOnCancelListener

public boolean addOnCancelListener (DialogInterface.OnCancelListener listener)

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(OnClickListener).

Parameters
listener DialogInterface.OnCancelListener

Returns
boolean

addOnDismissListener

public boolean addOnDismissListener (DialogInterface.OnDismissListener listener)

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

Parameters
listener DialogInterface.OnDismissListener

Returns
boolean

addOnNegativeButtonClickListener

public boolean addOnNegativeButtonClickListener (View.OnClickListener listener)

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

Parameters
listener View.OnClickListener

Returns
boolean

addOnPositiveButtonClickListener

public boolean addOnPositiveButtonClickListener (View.OnClickListener listener)

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

Parameters
listener View.OnClickListener

Returns
boolean

clearOnCancelListeners

public void clearOnCancelListeners ()

Removes all listeners added via addOnCancelListener(OnCancelListener).

clearOnDismissListeners

public void clearOnDismissListeners ()

Removes all listeners added via addOnDismissListener(OnDismissListener).

clearOnNegativeButtonClickListeners

public void clearOnNegativeButtonClickListeners ()

Removes all listeners added via addOnNegativeButtonClickListener(OnClickListener).

clearOnPositiveButtonClickListeners

public void clearOnPositiveButtonClickListeners ()

Removes all listeners added via addOnPositiveButtonClickListener(OnClickListener).

getHour

public int getHour ()

Returns the hour of day in the range [0, 23].

Returns
int

getInputMode

public int getInputMode ()

Returns
int

getMinute

public int getMinute ()

Returns the minute in the range [0, 59].

Returns
int

onCancel

public void onCancel (DialogInterface dialogInterface)

Parameters
dialogInterface DialogInterface

onCreate

public void onCreate (Bundle bundle)

Parameters
bundle Bundle

onCreateDialog

public Dialog onCreateDialog (Bundle bundle)

Parameters
bundle Bundle

Returns
Dialog

onCreateView

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

Parameters
layoutInflater LayoutInflater

viewGroup ViewGroup

bundle Bundle

Returns
View

onDestroyView

public void onDestroyView ()

onDismiss

public void onDismiss (DialogInterface dialogInterface)

Parameters
dialogInterface DialogInterface

onSaveInstanceState

public void onSaveInstanceState (Bundle bundle)

Parameters
bundle Bundle

onViewCreated

public void onViewCreated (View view, 
                Bundle bundle)

Parameters
view View

bundle Bundle

removeOnCancelListener

public boolean removeOnCancelListener (DialogInterface.OnCancelListener listener)

Removes a listener previously added via addOnCancelListener(OnCancelListener).

Parameters
listener DialogInterface.OnCancelListener

Returns
boolean

removeOnDismissListener

public boolean removeOnDismissListener (DialogInterface.OnDismissListener listener)

Removes a listener previously added via addOnDismissListener(OnDismissListener).

Parameters
listener DialogInterface.OnDismissListener

Returns
boolean

removeOnNegativeButtonClickListener

public boolean removeOnNegativeButtonClickListener (View.OnClickListener listener)

Removes a listener previously added via addOnNegativeButtonClickListener(OnClickListener).

Parameters
listener View.OnClickListener

Returns
boolean

removeOnPositiveButtonClickListener

public boolean removeOnPositiveButtonClickListener (View.OnClickListener listener)

Removes a listener previously added via addOnPositiveButtonClickListener(OnClickListener).

Parameters
listener View.OnClickListener

Returns
boolean

setCancelable

public void setCancelable (boolean cancelable)

Parameters
cancelable boolean

setHour

public void setHour (int hour)

Sets the hour of day in the range [0, 23].

Parameters
hour int

setMinute

public void setMinute (int minute)

Sets the minute in the range [0, 59].

Parameters
minute int