2

RowsSupportFragment onItemSelected() callback gets called by default when page loads for the first time, even though the item is not selected and focus is on some other element.

I have a ui where there is button and a RowsSupportFragment at bottom of the screen. When the activity loads for first time, onItemSelected() of RowsSupportFragment gets called by default by passing in first item of the RowsSupportFragment as item. Thought the first item hasn't got the focus yet (or) is being selected.

And now when I press D-pad down and move to RowsSupportFragment, the first item has focus and is selected but onItemSelected() callback is not triggered, the subsequent callbacks when I move to next item are triggered.

As per the documentation.

/**
 * Interface for receiving notification when a row or item becomes selected. The concept of
 * current selection is different than focus.  A row or item can be selected without having focus;
 * for example, when a row header view gains focus then the corresponding row view becomes selected.
 */
public interface BaseOnItemViewSelectedListener<T> {

    /**
     * Called when a row or a new item becomes selected.
     * <p>
     * For a non {@link ListRow} case, parameter item may be null.  Event is fired when
     * selection changes between rows, regardless if row view has focus or not.
     * <p>
     * For a {@link ListRow} case, parameter item is null if the list row is empty.
     * </p>
     * <p>
     * In the case of a grid, the row parameter is always null.
     * </p>
     * <li>
     * Row has focus: event is fired when focus changes between children of the row.
     * </li>
     * <li>
     * No row has focus: the event is fired with the currently selected row and last
     * focused item in the row.
     * </li>
     *
     * @param itemViewHolder The view holder of the item that is currently selected.
     * @param item The item that is currently selected.
     * @param rowViewHolder The view holder of the row that is currently selected.
     * @param row The row that is currently selected.
     */
    public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
                               RowPresenter.ViewHolder rowViewHolder, T row);
}

But I don't have any headers associated with RowsSupportFragment.

How do I change this behaviour ?

AndroidDev
  • 1,485
  • 2
  • 18
  • 33

0 Answers0