我遇到了android leanback RowsFragment焦点的问题。我在相同的RowsFragment中添加了两种不同类型的适配器(下面附带代码)但是当按下向上按钮(电视遥控器DPad向上按钮)以获得焦点在上面的行时,焦点转到顶部栏导航。
//我的示例代码 -
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));
}
}
}
我的布局文件是:
<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>
答案 0 :(得分:0)
将焦点添加到MyCustomPresenter()和MyCustomPresenter1()中的卡片展示器。
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
cardView.setFocusable(true);
cardView.setFocusableInTouchMode(true);
}