Picker
public class Picker extends FrameLayout
| java.lang.Object | ||||
| ↳ | 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 |
|---|
public interface Picker.PickerValueListenerListener for |
Public constructors |
|---|
Picker(@NonNull Context context, @Nullable AttributeSet attributeSet)Creates a Picker widget. |
Picker(Creates a Picker widget. |
Public methods |
|
|---|---|
void |
Register a callback to be invoked when the picker's value has changed. |
boolean |
dispatchKeyEvent(KeyEvent event) |
float |
Returns number of visible items showing in a column when it's activated. |
@Nullable PickerColumn |
getColumnAt(int colIndex)Get nth PickerColumn. |
int |
Get number of PickerColumns. |
final @LayoutRes int |
Classes extending |
final @IdRes int |
Returns the |
int |
Get current activated column index. |
final CharSequence |
This method is deprecated. Use |
final @NonNull 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. |
void |
onColumnValueChanged(int columnIndex, int newValue)Classes extending |
void |
Remove a previously installed value changed callback |
void |
requestChildFocus(View child, View focused) |
void |
setActivated(boolean activated) |
void |
setActivatedVisibleItemCount(float visiblePickerItems)Changes number of visible items showing in a column when it's activated. |
void |
setColumnAt(int columnIndex, @NonNull PickerColumn column)When column labels change or column range changes, call this function to re-populate the selection list. |
void |
setColumnValue(int columnIndex, int value, boolean runAnimation)Manually set current value of a column. |
void |
setColumns(@NonNull List<PickerColumn> columns)Set columns and create Views. |
final void |
setPickerItemLayoutId(@LayoutRes int pickerItemLayoutId)Sets the layout to use for picker items. |
final void |
setPickerItemTextViewId(@IdRes int textViewId)Sets the |
void |
setSelectedColumn(int columnIndex)Change current selected column. |
final void |
setSeparator(@NonNull CharSequence separator)Sets separator String between Picker columns. |
final void |
setSeparators(@NonNull List<CharSequence> separators)Sets the list of separators that will be populated between the Picker columns. |
void |
setVisibleItemCount(float pickerItems)Changes number of visible items showing in a column when it's not activated. |
Protected methods |
|
|---|---|
int |
Classes extending |
boolean |
onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
Public methods
addOnValueChangedListener
public void addOnValueChangedListener(@NonNull Picker.PickerValueListener listener)
Register a callback to be invoked when the picker's value has changed.
| Parameters | |
|---|---|
@NonNull Picker.PickerValueListener listener |
The callback to ad |
getActivatedVisibleItemCount
public float getActivatedVisibleItemCount()
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
public @Nullable PickerColumn getColumnAt(int colIndex)
Get nth PickerColumn.
| Parameters | |
|---|---|
int colIndex |
Index of PickerColumn. |
| Returns | |
|---|---|
@Nullable PickerColumn |
PickerColumn at colIndex or null if |
getColumnsCount
public int getColumnsCount()
Get number of PickerColumns.
| Returns | |
|---|---|
int |
Number of PickerColumns or 0 if |
getPickerItemLayoutId
public final @LayoutRes int getPickerItemLayoutId()
Classes extending Picker can call setPickerItemLayoutId to supply the Picker's item's layout id
getPickerItemTextViewId
public final @IdRes int getPickerItemTextViewId()
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
public int getSelectedColumn()
Get current activated column index.
| Returns | |
|---|---|
int |
Current activated column index. |
public final CharSequencegetSeparator()
Gets separator string between columns.
| Returns | |
|---|---|
CharSequence |
The separator that will be populated between all the Picker columns. |
getSeparators
public final @NonNull List<CharSequence> getSeparators()
Returns the list of separators that will be populated between the picker column fields.
| Returns | |
|---|---|
@NonNull List<CharSequence> |
The list of separators populated between the picker column fields. |
getVisibleItemCount
public float getVisibleItemCount()
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
public 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 and or setColumnAt. Subclass should not directly call setCurrentValue which does not update internal state or notify listeners.
| Parameters | |
|---|---|
int columnIndex |
index of which column was changed. |
int newValue |
A new value desired to be set on the column. |
removeOnValueChangedListener
public void removeOnValueChangedListener(
@NonNull Picker.PickerValueListener listener
)
Remove a previously installed value changed callback
| Parameters | |
|---|---|
@NonNull Picker.PickerValueListener listener |
The callback to remove. |
setActivatedVisibleItemCount
public void setActivatedVisibleItemCount(float visiblePickerItems)
Changes number of visible items showing in a column when it's activated. The default value is 3.
| Parameters | |
|---|---|
float visiblePickerItems |
Number of visible items showing in a column when it's activated. |
setColumnAt
public void setColumnAt(int columnIndex, @NonNull PickerColumn column)
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 | |
|---|---|
int columnIndex |
Index of column to update. |
@NonNull PickerColumn column |
New column to update. |
setColumnValue
public void setColumnValue(int columnIndex, int value, boolean runAnimation)
Manually set current value of a column. The function will update UI and notify listeners.
| Parameters | |
|---|---|
int columnIndex |
Index of column to update. |
int value |
New value of the column. |
boolean runAnimation |
True to scroll to the value or false otherwise. |
setColumns
public void setColumns(@NonNull List<PickerColumn> columns)
Set columns and create Views.
| Parameters | |
|---|---|
@NonNull List<PickerColumn> columns |
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
public final void setPickerItemLayoutId(@LayoutRes int pickerItemLayoutId)
Sets the layout to use for picker items.
| Parameters | |
|---|---|
@LayoutRes int pickerItemLayoutId |
Layout resource id to use for picker items. |
setPickerItemTextViewId
public final void setPickerItemTextViewId(@IdRes int textViewId)
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}.
| Parameters | |
|---|---|
@IdRes int textViewId |
View id of TextView inside a Picker item, or 0 if the Picker item is a TextView. |
setSelectedColumn
public void setSelectedColumn(int columnIndex)
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 | |
|---|---|
int columnIndex |
Index of column to activate. |
setSeparator
public final void setSeparator(@NonNull CharSequence separator)
Sets separator String between Picker columns.
| Parameters | |
|---|---|
@NonNull CharSequence separator |
Separator String between Picker columns. |
setSeparators
public final void setSeparators(@NonNull List<CharSequence> separators)
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 | |
|---|---|
@NonNull List<CharSequence> separators |
The list of separators to be populated between the Picker columns. |
setVisibleItemCount
public void setVisibleItemCount(float pickerItems)
Changes number of visible items showing in a column when it's not activated. The default value is 1.
| Parameters | |
|---|---|
float pickerItems |
Number of visible items showing in a column when it's not activated. |
Protected methods
getPickerItemHeightPixels
protected int getPickerItemHeightPixels()
Classes extending Picker can choose to override this method to supply the Picker's column's single item height in pixels.
onRequestFocusInDescendants
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)