How To Write A Custom Leanbacks Verticalgridview In Android Tv?
I want to implement a Row from the Details screen of the Leanback library into a customized screen. The row will be the one below. I have already implemented the HorizontalGridView
Solution 1:
To solve this, use a VerticalGridView
instead of a HorizontalGridView
.
<android.support.v17.leanback.widget.VerticalGridView
android:id="@+id/detail_related"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
To set the ArrayObjectAdapter
to the VerticalGridView
, use an ItemBridgeAdapter
.
ItemBridgeAdapteradapter=newItemBridgeAdapter();
adapter.setAdapter(mRowsAdapter);
adapter.setPresenter(newSinglePresenterSelector(newListRowPresenter()));
mBinding.detailRelated.setAdapter(adapter);
Solution 2:
If your view is a custom one, make sure you add the following to your customized view to get focus:
setFocusable(true);
setFocusableInTouchMode(true);
Solution 3:
The problem in custom view is you need to add the focus change listener in the java code.Add the focus listener inside the adapter to the root view of the adapter items.
Add focusable for the rootview in the oncreate of the adapter items.
yourView.setFocusable(true);
yourView.setFocusableInTouchMode(true);
Then in the onBind add the focuschangeListener.
yourRootView.setOnFocusChangeListener(newView.OnFocusChangeListener() {
@OverridepublicvoidonFocusChange(View v, boolean hasFocus) {
if(hasFocus){
//focus gained
}else {
//focus lost
}
}
});
Solution 4:
Try to put
android:descendantFocusability="afterDescendants"
in your .xml
file
<android.support.v17.leanback.widget.HorizontalGridViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:descendantFocusability="afterDescendants"/>
Post a Comment for "How To Write A Custom Leanbacks Verticalgridview In Android Tv?"