added in version 25.4.0
belongs to Maven artifact com.android.support:leanback-v17:28.0.0-alpha1

TimePicker

public class TimePicker
extends Picker

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.support.v17.leanback.widget.picker.Picker
           ↳ android.support.v17.leanback.widget.picker.TimePicker


TimePicker is a direct subclass of Picker.

This class is a widget for selecting time and displays it according to the formatting for the current system locale. The time can be selected by hour, minute, and AM/PM picker columns. The AM/PM mode is determined by either explicitly setting the current mode through setIs24Hour(boolean) or the widget attribute is24HourFormat (true for 24-hour mode, false for 12-hour mode). Otherwise, TimePicker retrieves the mode based on the current context. In 24-hour mode, TimePicker displays only the hour and minute columns.

This widget can show the current time as the initial value if useCurrentTime is set to true. Each individual time picker field can be set at any time by calling setHour(int), setMinute(int) using 24-hour time format. The time format can also be changed at any time by calling setIs24Hour(boolean), and the AM/PM picker column will be activated or deactivated accordingly.

Summary

XML attributes

lbTimePicker_is24HourFormat  
lbTimePicker_useCurrentTime  

Inherited constants

From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.View

Public constructors

TimePicker(Context context, AttributeSet attrs)

Constructor called when inflating a TimePicker widget.

TimePicker(Context context, AttributeSet attrs, int defStyleAttr)

Constructor called when inflating a TimePicker widget.

Public methods

int getHour()

Returns the currently selected hour using 24-hour time.

int getMinute()

Returns the currently selected minute.

boolean is24Hour()
boolean isPm()

Only meaningful for a 12-hour time.

void onColumnValueChanged(int columnIndex, int newValue)

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

void setHour(int hour)

Sets the currently selected hour using a 24-hour time.

void setIs24Hour(boolean is24Hour)

Sets whether this widget displays a 24-hour mode or a 12-hour mode with an AM/PM picker.

void setMinute(int minute)

Sets the currently selected minute.

Inherited methods

From class android.support.v17.leanback.widget.picker.Picker
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

XML attributes

lbTimePicker_is24HourFormat

lbTimePicker_useCurrentTime

Public constructors

TimePicker

added in version 25.4.0
TimePicker (Context context, 
                AttributeSet attrs)

Constructor called when inflating a TimePicker widget. This version uses a default style of 0, so the only attribute values applied are those in the Context's Theme and the given AttributeSet.

Parameters
context Context: the context this TimePicker widget is associated with through which we can access the current theme attributes and resources

attrs AttributeSet: the attributes of the XML tag that is inflating the TimePicker widget

TimePicker

added in version 25.4.0
TimePicker (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Constructor called when inflating a TimePicker widget.

Parameters
context Context: the context this TimePicker widget is associated with through which we can access the current theme attributes and resources

attrs AttributeSet: the attributes of the XML tag that is inflating the TimePicker widget

defStyleAttr int: An attribute in the current theme that contains a reference to a style resource that supplies default values for the widget. Can be 0 to not look for defaults.

Public methods

getHour

added in version 25.4.0
int getHour ()

Returns the currently selected hour using 24-hour time.

Returns
int the currently selected hour in the range (0-23)

See also:

getMinute

added in version 25.4.0
int getMinute ()

Returns the currently selected minute.

Returns
int the currently selected minute, in the range (0-59)

See also:

is24Hour

added in version 25.4.0
boolean is24Hour ()

Returns
boolean true if this widget displays time in 24-hour mode, false otherwise.

isPm

added in version 25.4.0
boolean isPm ()

Only meaningful for a 12-hour time.

Returns
boolean true if the currently selected time is in PM, false if the currently selected time in in AM.

onColumnValueChanged

added in version 25.4.0
void onColumnValueChanged (int columnIndex, 
                int newValue)

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 setCurrentValue(int) which does not update internal state or notify listeners.

Parameters
columnIndex int: index of which column was changed.

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

setHour

added in version 25.4.0
void setHour (int hour)

Sets the currently selected hour using a 24-hour time.

Parameters
hour int: the hour to set, in the range (0-23)

Value is 23 or less.

See also:

setIs24Hour

added in version 25.4.0
void setIs24Hour (boolean is24Hour)

Sets whether this widget displays a 24-hour mode or a 12-hour mode with an AM/PM picker.

Parameters
is24Hour boolean: true to display in 24-hour mode, false ti display in 12-hour mode with AM/PM.

See also:

setMinute

added in version 25.4.0
void setMinute (int minute)

Sets the currently selected minute.

Parameters
minute int: the minute to set, in the range (0-59)

Value is 59 or less.

See also: