Most visited

Recently visited

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


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 XML attributes

    From class android.widget.FrameLayout
    From class android.view.ViewGroup
    From class android.view.View

    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)

    Dispatch a key event to the next view on the focus path.

    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()

    Gets separator string between columns.

    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)

    Called when a child of this parent wants focus

    void setActivated(boolean activated)

    Changes the activated state of this view.

    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 seperator)

    Sets separator String between 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)

    Look for a descendant to call requestFocus() on.

    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

    Picker (Context context, 
                    AttributeSet attrs, 
                    int defStyleAttr)

    Creates a Picker widget.

    Public methods

    addOnValueChangedListener

    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)

    Dispatch a key event to the next view on the focus path. This path runs from the top of the view tree down to the currently focused view. If this view has focus, it will dispatch to itself. Otherwise it will dispatch the next node down the focus path. This method also fires any key listeners.

    Parameters
    event KeyEvent: The key event to be dispatched.
    Returns
    boolean True if the event was handled, false otherwise.

    getActivatedVisibleItemCount

    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

    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

    int getColumnsCount ()

    Get number of PickerColumns.

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

    getPickerItemLayoutId

    int getPickerItemLayoutId ()

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

    Returns
    int

    getPickerItemTextViewId

    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

    int getSelectedColumn ()

    Get current activated column index.

    Returns
    int Current activated column index.

    getSeparator

    CharSequence getSeparator ()

    Gets separator string between columns.

    Returns
    CharSequence

    getVisibleItemCount

    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

    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

    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)

    Called when a child of this parent wants focus

    Parameters
    child View: The child of this ViewParent that wants focus. This view will contain the focused view. It is not necessarily the view that actually has focus.
    focused View: The view that is a descendant of child that actually has focus

    setActivated

    void setActivated (boolean activated)

    Changes the activated state of this view. A view can be activated or not. Note that activation is not the same as selection. Selection is a transient property, representing the view (hierarchy) the user is currently interacting with. Activation is a longer-term state that the user can move views in and out of. For example, in a list view with single or multiple selection enabled, the views in the current selection set are activated. (Um, yeah, we are deeply sorry about the terminology here.) The activated state is propagated down to children of the view it is set on.

    Parameters
    activated boolean: true if the view must be activated, false otherwise

    setActivatedVisibleItemCount

    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

    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

    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

    void setColumns (List<PickerColumn> columns)

    Set columns and create Views.

    Parameters
    columns List: PickerColumns to be shown in the Picker.

    setPickerItemTextViewId

    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

    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

    void setSeparator (CharSequence seperator)

    Sets separator String between Picker columns.

    Parameters
    seperator CharSequence: Separator String between Picker columns.

    setVisibleItemCount

    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

    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)

    Look for a descendant to call requestFocus() on. Called by requestFocus(int, android.graphics.Rect) when it wants to request focus within its children. Override this to customize how your ViewGroup requests focus within its children.

    Parameters
    direction int: One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT
    previouslyFocusedRect Rect: The rectangle (in this View's coordinate system) to give a finer grained hint about where focus is coming from. May be null if there is no hint.
    Returns
    boolean Whether focus was taken.
  • Hooray!