Sumit T
Sumit T

Reputation: 1363

Issue with request focus on RowsFragment android Leanback library?

I am having an issue with android leanback RowsFragment focus. I am adding two different types of adapters in same RowsFragment(attached code below) but when pressing up button (tv remotes DPad up button) to get focus on above row, the focus goes to top bar navigation.

//My Sample code -

MyRowFragment extends RowsFragment
    {
        private SparseArrayObjectAdapter myRowsAdapter;
        @Override
        public void onViewCreated (View view, Bundle savedInstanceState){
        super.onViewCreated(view, savedInstanceState);
        loadDataRows();
    }

    private void loadDataRows() {
// got some logic to download data 
        for (MyDataType data : MyDataTypeList) {
            ArrayObjectAdapter rowAdapter;

            //conditionToCheck is boolean to check some condition
            if (conditionToCheck) {
                rowAdapter =
                        new ArrayObjectAdapter(new MyCustomPresenter(value, value1));
            } else {
                rowAdapter =
                        new ArrayObjectAdapter(MyCustomPresentor1(value, value1));
            }

            rowAdapter.add(data);

            myRowsAdapter.set(rowKey, new ListRow(rowAdapter));

        }
    }
}

And my layout file is :

<com.github.ksoichiro.android.observablescrollview.ObservableScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none">

            <FrameLayout
                android:id="@+id/rowsContainer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
        </LinearLayout>
    </com.github.ksoichiro.android.observablescrollview.ObservableScrollView>

Upvotes: 0

Views: 1639

Answers (1)

Sharath kumar
Sharath kumar

Reputation: 4132

Add focusable to the card presenter in MyCustomPresenter() and MyCustomPresenter1().

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    cardView.setFocusable(true);
    cardView.setFocusableInTouchMode(true);
}

Upvotes: 1

Related Questions