我正在尝试创建一个类似于 Youtube 应用程序的 Android 电视应用程序。我正在使用Sofa库来做到这一点。现在,当我试图在没有焦点的情况下显示单个项目的标题时,问题就来RowsFragment
了RowsFragment
。以下是将数据集加载到browseFragment的代码
private void loadRowsCustom() {
adapter = new ArrayObjectAdapter();
int split = 3;
int rowsFragmentCount = videoList.size() / split + (videoList.size() % split != 0 ? 1 : 0);
for (int i = 0; i < rowsFragmentCount; i++) {
ListRowPresenter lrp = new ListRowPresenter(FocusHighlight.ZOOM_FACTOR_LARGE);
ArrayObjectAdapter rowsAdapter = new ArrayObjectAdapter(lrp);
String category = "Category";
for (int j = 0; j < split && (i * split + j) < videoList.size(); j++) {
Video[] videos = videoList.get(i * split + j);
ArrayObjectAdapter rowCollAdapter = new ArrayObjectAdapter(new VideoPresenter());
rowCollAdapter.addAll(0, Arrays.asList(videos));
ListRow row = new ListRow(new HeaderItem(videos[0].category),rowCollAdapter);
rowsAdapter.add(row);
category = videos[0].category;
}
ArrayObjectAdapter fragmentAdapter = new ArrayObjectAdapter();
RowsSupportFragment rowsSupportFragment = new RowsSupportFragment();
rowsSupportFragment.setAdapter(rowsAdapter);
rowsSupportFragment.enableRowScaling(false);
fragmentAdapter.add(rowsSupportFragment);
adapter.add(new ListRow(new HeaderItem(category), fragmentAdapter));
}
browseSupportFragment.setAdapter(adapter);
browseSupportFragment.setHeadersState(BrowseSupportFragment.HEADERS_ENABLED);
browseSupportFragment.setOnSearchClickedListener(searchClickListener);
browseSupportFragment.setOnItemViewClickedListener(browseClickListener);
browseSupportFragment.setTitle("Google Videos");
}
所需的和当前的实现如下面的屏幕截图所示: