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

Picker

public class Picker
extends FrameLayout

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


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:

  • 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.
  • isActivated() is false: Picker shows one item vertically (see getVisibleItemCount()) on all columns. The size of Picker shrinks.

    Summary

    Nested classes

    interface Picker.PickerValueListener

     

    Inherited constants

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

    Inherited fields

    From class android.view.View

    Public constructors

    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 choose to override this method 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 was deprecated in API level 27.1.0. 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 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

    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

    Public constructors

    Picker

    added in version 24.1.0
    Picker (Context context, 
                    AttributeSet attrs, 
                    int defStyleAttr)

    Creates a Picker widget.

    Parameters
    context Context

    attrs AttributeSet

    defStyleAttr int

    Public methods

    addOnValueChangedListener

    added in version 24.1.0
    void addOnValueChangedListener (Picker.PickerValueListener listener)

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

    Parameters
    listener Picker.PickerValueListener: The callback to ad

    dispatchKeyEvent

    boolean dispatchKeyEvent (KeyEvent event)

    Parameters
    event KeyEvent

    Returns
    boolean

    getActivatedVisibleItemCount

    added in version 24.1.0
    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

    added in version 24.1.0
    PickerColumn getColumnAt (int colIndex)

    Get nth PickerColumn.

    Parameters
    colIndex int: Index of PickerColumn.

    Returns
    PickerColumn PickerColumn at colIndex or null if setColumns(List) is not called yet.

    getColumnsCount

    added in version 24.1.0
    int getColumnsCount ()

    Get number of PickerColumns.

    Returns
    int Number of PickerColumns or 0 if setColumns(List) is not called yet.

    getPickerItemLayoutId

    added in version 24.1.0
    int getPickerItemLayoutId ()

    Classes extending Picker can choose to override this method to supply the Picker's item's layout id

    Returns
    int

    getPickerItemTextViewId

    added in version 24.1.0
    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}.

    Returns
    int

    getSelectedColumn

    added in version 24.1.0
    int getSelectedColumn ()

    Get current activated column index.

    Returns
    int Current activated column index.

    getSeparator

    added in version 24.1.0
    CharSequence getSeparator ()

    This method was deprecated in API level 27.1.0.
    Use getSeparators()

    Gets separator string between columns.

    Returns
    CharSequence The separator that will be populated between all the Picker columns.

    getSeparators

    added in version 27.1.0
    List<CharSequence> getSeparators ()

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

    Returns
    List<CharSequence> The list of separators populated between the picker column fields.

    getVisibleItemCount

    added in version 24.1.0
    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

    added in version 24.1.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.

    removeOnValueChangedListener

    added in version 24.1.0
    void removeOnValueChangedListener (Picker.PickerValueListener listener)

    Remove a previously installed value changed callback

    Parameters
    listener Picker.PickerValueListener: The callback to remove.

    requestChildFocus

    void requestChildFocus (View child, 
                    View focused)

    Parameters
    child View

    focused View

    setActivated

    void setActivated (boolean activated)

    Parameters
    activated boolean

    setActivatedVisibleItemCount

    added in version 24.1.0
    void setActivatedVisibleItemCount (float visiblePickerItems)

    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

    added in version 24.1.0
    void setColumnAt (int columnIndex, 
                    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
    columnIndex int: Index of column to update.

    column PickerColumn: New column to update.

    setColumnValue

    added in version 24.1.0
    void setColumnValue (int columnIndex, 
                    int value, 
                    boolean runAnimation)

    Manually set current value of a column. The function will update UI and notify listeners.

    Parameters
    columnIndex int: Index of column to update.

    value int: New value of the column.

    runAnimation boolean: True to scroll to the value or false otherwise.

    setColumns

    added in version 24.1.0
    void setColumns (List<PickerColumn> columns)

    Set columns and create Views.

    Parameters
    columns List: 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).

    setPickerItemTextViewId

    added in version 24.1.0
    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}.

    Parameters
    textViewId int: View id of TextView inside a Picker item, or 0 if the Picker item is a TextView.

    setSelectedColumn

    added in version 24.1.0
    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
    columnIndex int: Index of column to activate.

    setSeparator

    added in version 24.1.0
    void setSeparator (CharSequence separator)

    Sets separator String between Picker columns.

    Parameters
    separator CharSequence: Separator String between Picker columns.

    setSeparators

    added in version 27.1.0
    void setSeparators (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(List). 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 List: The list of separators to be populated between the Picker columns.

    setVisibleItemCount

    added in version 24.1.0
    void setVisibleItemCount (float pickerItems)

    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 methods

    getPickerItemHeightPixels

    added in version 24.1.0
    int getPickerItemHeightPixels ()

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

    Returns
    int

    onRequestFocusInDescendants

    boolean onRequestFocusInDescendants (int direction, 
                    Rect previouslyFocusedRect)

    Parameters
    direction int

    previouslyFocusedRect Rect

    Returns
    boolean