Picker
class Picker : FrameLayout
| kotlin.Any | ||||
| ↳ | android.view.View | |||
| ↳ | android.view.ViewGroup | |||
| ↳ | android.widget.FrameLayout | |||
| ↳ | androidx.leanback.widget.picker.Picker |
DatePicker |
|
PinPicker |
|
TimePicker |
|
Picker is a widget showing multiple customized PickerColumns. The PickerColumns are initialized in setColumns. Call setColumnAt if the column value range or labels change. Call setColumnValue to update the current value of PickerColumn.
Picker has two states and will change height:
isActivatedis true: Picker shows typically three items vertically (seegetActivatedVisibleItemCount}. Columns other thangetSelectedColumnstill shows one item if the Picker is focused. On a touch screen device, the Picker will not get focus so it always show three items on all columns. On a non-touch device (a TV), the Picker will show three items only on currently activated column. If the Picker has focus, it will intercept DPAD directions and select activated column.isActivatedis false: Picker shows one item vertically (seegetVisibleItemCount) on all columns. The size of Picker shrinks.
Summary
Nested types |
|---|
interface Picker.PickerValueListenerListener for |
Public constructors |
|---|
Picker(context: Context, attributeSet: AttributeSet?)Creates a Picker widget. |
Picker(context: Context, attrs: AttributeSet?, defStyleAttr: Int)Creates a Picker widget. |
Public functions |
|
|---|---|
Unit |
Register a callback to be invoked when the picker's value has changed. |
Boolean |
dispatchKeyEvent(event: KeyEvent!) |
Float |
Returns number of visible items showing in a column when it's activated. |
PickerColumn? |
getColumnAt(colIndex: Int)Get nth PickerColumn. |
Int |
Get number of PickerColumns. |
@LayoutRes Int |
Classes extending |
@IdRes Int |
Returns the |
Int |
Get current activated column index. |
CharSequence! |
This function is deprecated. Use |
(Mutable)List<CharSequence!> |
Returns the list of separators that will be populated between the picker column fields. |
Float |
Returns number of visible items showing in a column when it's not activated. |
Unit |
onColumnValueChanged(columnIndex: Int, newValue: Int)Classes extending |
Unit |
Remove a previously installed value changed callback |
Unit |
requestChildFocus(child: View!, focused: View!) |
Unit |
setActivated(activated: Boolean) |
Unit |
setActivatedVisibleItemCount(visiblePickerItems: Float)Changes number of visible items showing in a column when it's activated. |
Unit |
setColumnAt(columnIndex: Int, column: PickerColumn)When column labels change or column range changes, call this function to re-populate the selection list. |
Unit |
setColumnValue(columnIndex: Int, value: Int, runAnimation: Boolean)Manually set current value of a column. |
Unit |
setColumns(columns: (Mutable)List<PickerColumn!>)Set columns and create Views. |
Unit |
setPickerItemLayoutId(pickerItemLayoutId: @LayoutRes Int)Sets the layout to use for picker items. |
Unit |
setPickerItemTextViewId(textViewId: @IdRes Int)Sets the |
Unit |
setSelectedColumn(columnIndex: Int)Change current selected column. |
Unit |
setSeparator(separator: CharSequence)Sets separator String between Picker columns. |
Unit |
setSeparators(separators: (Mutable)List<CharSequence!>)Sets the list of separators that will be populated between the Picker columns. |
Unit |
setVisibleItemCount(pickerItems: Float)Changes number of visible items showing in a column when it's not activated. |
Protected functions |
|
|---|---|
Int |
Classes extending |
Boolean |
onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!) |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
Picker
Picker(context: Context, attributeSet: AttributeSet?)
Creates a Picker widget.
Picker
Picker(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
Creates a Picker widget.
Public functions
addOnValueChangedListener
fun addOnValueChangedListener(listener: Picker.PickerValueListener): Unit
Register a callback to be invoked when the picker's value has changed.
| Parameters | |
|---|---|
listener: Picker.PickerValueListener |
The callback to ad |
getActivatedVisibleItemCount
fun getActivatedVisibleItemCount(): Float
Returns number of visible items showing in a column when it's activated. The default value is 3.
| Returns | |
|---|---|
Float |
Number of visible items showing in a column when it's activated. |
getColumnAt
fun getColumnAt(colIndex: Int): PickerColumn?
Get nth PickerColumn.
| Parameters | |
|---|---|
colIndex: Int |
Index of PickerColumn. |
| Returns | |
|---|---|
PickerColumn? |
PickerColumn at colIndex or null if |
getColumnsCount
fun getColumnsCount(): Int
Get number of PickerColumns.
| Returns | |
|---|---|
Int |
Number of PickerColumns or 0 if |
getPickerItemLayoutId
fun getPickerItemLayoutId(): @LayoutRes Int
Classes extending Picker can call setPickerItemLayoutId to supply the Picker's item's layout id
getPickerItemTextViewId
fun getPickerItemTextViewId(): @IdRes Int
Returns the Picker's item's TextView's id from within the layout provided by getPickerItemLayoutId or 0 if the layout provided by getPickerItemLayoutId is a {link TextView}.
getSelectedColumn
fun getSelectedColumn(): Int
Get current activated column index.
| Returns | |
|---|---|
Int |
Current activated column index. |
fungetSeparator(): CharSequence!
Gets separator string between columns.
| Returns | |
|---|---|
CharSequence! |
The separator that will be populated between all the Picker columns. |
getSeparators
fun getSeparators(): (Mutable)List<CharSequence!>
Returns the list of separators that will be populated between the picker column fields.
| Returns | |
|---|---|
(Mutable)List<CharSequence!> |
The list of separators populated between the picker column fields. |
getVisibleItemCount
fun getVisibleItemCount(): Float
Returns number of visible items showing in a column when it's not activated. The default value is 1.
| Returns | |
|---|---|
Float |
Number of visible items showing in a column when it's not activated. |
onColumnValueChanged
fun onColumnValueChanged(columnIndex: Int, newValue: Int): Unit
Classes extending Picker can override this function to supply the behavior when a list has been scrolled. Subclass may call setColumnValue and or setColumnAt. Subclass should not directly call setCurrentValue which does not update internal state or notify listeners.
removeOnValueChangedListener
fun removeOnValueChangedListener(listener: Picker.PickerValueListener): Unit
Remove a previously installed value changed callback
| Parameters | |
|---|---|
listener: Picker.PickerValueListener |
The callback to remove. |
setActivatedVisibleItemCount
fun setActivatedVisibleItemCount(visiblePickerItems: Float): Unit
Changes number of visible items showing in a column when it's activated. The default value is 3.
| Parameters | |
|---|---|
visiblePickerItems: Float |
Number of visible items showing in a column when it's activated. |
setColumnAt
fun setColumnAt(columnIndex: Int, column: PickerColumn): Unit
When column labels change or column range changes, call this function to re-populate the selection list. Note this function cannot be called from RecyclerView layout/scroll pass.
| Parameters | |
|---|---|
columnIndex: Int |
Index of column to update. |
column: PickerColumn |
New column to update. |
setColumnValue
fun setColumnValue(columnIndex: Int, value: Int, runAnimation: Boolean): Unit
Manually set current value of a column. The function will update UI and notify listeners.
setColumns
fun setColumns(columns: (Mutable)List<PickerColumn!>): Unit
Set columns and create Views.
| Parameters | |
|---|---|
columns: (Mutable)List<PickerColumn!> |
The actual focusable columns of a picker which are scrollable if the field takes more than one value (e.g. for a DatePicker, day, month, and year fields and for TimePicker, hour, minute, and am/pm fields form the columns). |
setPickerItemLayoutId
fun setPickerItemLayoutId(pickerItemLayoutId: @LayoutRes Int): Unit
Sets the layout to use for picker items.
setPickerItemTextViewId
fun setPickerItemTextViewId(textViewId: @IdRes Int): Unit
Sets the Picker's item's TextView's id from within the layout provided by getPickerItemLayoutId or 0 if the layout provided by getPickerItemLayoutId is a {link TextView}.
setSelectedColumn
fun setSelectedColumn(columnIndex: Int): Unit
Change current selected column. Picker shows multiple items on selected column if Picker has focus. Picker shows multiple items on all column if Picker has no focus (e.g. a Touchscreen screen).
| Parameters | |
|---|---|
columnIndex: Int |
Index of column to activate. |
setSeparator
fun setSeparator(separator: CharSequence): Unit
Sets separator String between Picker columns.
| Parameters | |
|---|---|
separator: CharSequence |
Separator String between Picker columns. |
setSeparators
fun setSeparators(separators: (Mutable)List<CharSequence!>): Unit
Sets the list of separators that will be populated between the Picker columns. The number of the separators should be either 1 indicating the same separator used between all the columns fields (and nothing will be placed before the first and after the last column), or must be one unit larger than the number of columns passed to setColumns. In the latter case, the list of separators corresponds to the positions before the first column all the way to the position after the last column. An empty string for a given position indicates no separators needs to be placed for that position, otherwise a TextView with the given String will be created and placed there.
| Parameters | |
|---|---|
separators: (Mutable)List<CharSequence!> |
The list of separators to be populated between the Picker columns. |
setVisibleItemCount
fun setVisibleItemCount(pickerItems: Float): Unit
Changes number of visible items showing in a column when it's not activated. The default value is 1.
| Parameters | |
|---|---|
pickerItems: Float |
Number of visible items showing in a column when it's not activated. |
Protected functions
getPickerItemHeightPixels
protected fun getPickerItemHeightPixels(): Int
Classes extending Picker can choose to override this method to supply the Picker's column's single item height in pixels.
onRequestFocusInDescendants
protected fun onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!): Boolean