是否可以将RowsSupportFragment的子类传递给BrowseSupportFragment的子类?

问题描述 投票:0回答:1

我想传递一个BrowseSupportFragment子类的RowsSupportFragment子类,因为我需要覆盖RowsSupportFragment中的一些方法来更改RowsSupportFragment的默认行为。

例如,要通过将setExpand()函数重写为true来始终显示行标题。

同样的问题适用于HeadersSupportFragment的子类。

kotlin android-tv leanback
1个回答
1
投票

没有测试过这个,但我相信它应该可行。

在你的BrowseSupportFragment中,为你的子类创建一个自定义的FragmentFactory并覆盖现有的ListRow配对,如下所示:

getMainFragmentRegistry().registerFragment(ListRow.class, new FragmentFactory<CustomRowsSupportFragment>() {
            @Override
            public CustomRowsSupportFragment createFragment(Object row) {
                return new CustomRowsSupportFragment();
            }
       }
);
© www.soinside.com 2019 - 2024. All rights reserved.