Android 12 Developer Preview is here! Try it out, and give us your feedback!

Picker

public class Picker
extends FrameLayout

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ androidx.leanback.widget.picker.Picker


Picker is a widget showing multiple customized PickerColumns. The PickerColumns are initialized in setColumns(List). Call setColumnAt(int, PickerColumn) if the column value range or labels change. Call setColumnValue(int, int, boolean) to update the current value of PickerColumn.

Picker has two states and will change height:

  • View.isActivated() is true: Picker shows typically three items vertically (see getActivatedVisibleItemCount()}. Columns other than getSelectedColumn() still 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.
  • View.isActivated() is false: Picker shows one item vertically (see getVisibleItemCount()) on all columns. The size of Picker shrinks.

    Summary

    Nested classes

    interface Picker.PickerValueListener

    Listener for Picker value changes. 

    Inherited constants

    Inherited fields

    Public constructors

    Picker(Context context, AttributeSet attributeSet)

    Creates a Picker widget.

    Picker(Context context, AttributeSet attrs, int defStyleAttr)

    Creates a Picker widget.

    Public methods

    void addOnValueChangedListener(Picker.PickerValueListener listener)

    Register a callback to be invoked when the picker's value has changed.

    boolean dispatchKeyEvent(KeyEvent event)
    float getActivatedVisibleItemCount()

    Returns number of visible items showing in a column when it's activated.

    PickerColumn getColumnAt(int colIndex)

    Get nth PickerColumn.

    int getColumnsCount()

    Get number of PickerColumns.

    final int getPickerItemLayoutId()

    Classes extending Picker can call setPickerItemLayoutId(int) to supply the Picker's item's layout id

    final 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}.

    int getSelectedColumn()

    Get current activated column index.

    final CharSequence getSeparator()

    This method is deprecated. Use getSeparators()

    final List<CharSequence> getSeparators()

    Returns the list of separators that will be populated between the picker column fields.

    float getVisibleItemCount()

    Returns number of visible items showing in a column when it's not activated.

    void onColumnValueChanged(int columnIndex, int newValue)

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

    void removeOnValueChangedListener(Picker.PickerValueListener listener)

    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, 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(List<PickerColumn> columns)

    Set columns and create Views.

    final void setPickerItemLayoutId(int pickerItemLayoutId)

    Sets the layout to use for picker items.

    final void setPickerItemTextViewId(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}.

    void setSelectedColumn(int columnIndex)

    Change current selected column.

    final void setSeparator(CharSequence separator)

    Sets separator String between Picker columns.

    final void setSeparators(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 getPickerItemHeightPixels()

    Classes extending Picker can choose to override this method to supply the Picker's column's single item height in pixels.

    boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)

    Inherited methods

    Public constructors

    Picker

    public Picker (Context context, 
                    AttributeSet attributeSet)

    Creates a Picker widget.

    Parameters
    context Context

    attributeSet AttributeSet

    Picker

    public Picker (Context context, 
                    AttributeSet attrs, 
                    int defStyleAttr)

    Creates a Picker widget.

    Parameters
    context Context

    attrs AttributeSet

    defStyleAttr int

    Public methods

    addOnValueChangedListener

    public void addOnValueChangedListener (Picker.PickerValueListener listener)