androidrowandroid-tvleanback

android leanback browseSupportFragment return wrong selectedPosition?


I am using a browseSupportFragment element in my android tv app having headers enabled and a single row for every header the problem is when i select the first item of every row by scrolling down, or when i select a header of the header list, the function getSelectedPosition return 0 always

it return the right index of row when i select the second item in the row

i am pretty sure that this is a bug !!

below the code of onItemSelected

 @Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object
        item, RowPresenter.ViewHolder rowViewHolder, Row row) {

    int pos = getSelectedPosition();//this return 0 if i scroll down between headers
 }

Solution

  • You will need to override it because for some reason it returns 0 by default.

        /**
        * Returns the selected position.
        */
        public int getSelectedPosition() {
            return 0;
        }
    

    You might need to override the setter as well because it is empty too.

        /**
         * Selects a Row.
         */
        public void setSelectedPosition(int rowPosition, boolean smooth) {
        }
    

    It seems leanback support was left a bit undercooked.