I'm trying to create an Android tv application similar to the Youtube application. and I am using the Sofa library to do that. Now the problem comes when I am trying to show the headers for individual items in the RowsFragment
even when the RowsFragment
doesn't have a focus. following is the code for loading the dataset into 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");
}
The required and the current implementation is described as in the screenshots below:
As Mayur Kaul already mentioned, u just need to call
mRowsFragment.setExpand(true)
But in this case everytime when onAttachedToWindow(...)
method would be called (see android.support.v17.leanback.app.RowsFragment
- ItemBridgeAdapter.AdapterListener mBridgeAdapterListener
), your header titles anyway would be hidden.
So final solution, witch worked for me it's just simply override setExpand()
method in your RowsFragment implementation like below:
@Override
public void setExpand(boolean expand) {
super.setExpand(true);
}
For those who are facing a similar problem, i finally managed to find a hack which will give the desired results. But for that you might need to get the source of BrowseSupportFragment
or in Sofa and modify the following line of code. I know its a bit of hack, but it get's the desired output.
For BrowseFragment: Notice the mRowsFragment.setExpand(true)
private void showHeaders(boolean show) {
if (DEBUG) Log.v(TAG, "showHeaders " + show);
mHeadersFragment.setHeadersEnabled(show);
setHeadersOnScreen(show);
setRowsAlignedLeft(!show);
if (mRowsFragment != null) {
mRowsFragment.setExpand(true);
} else if (mCurrentFragment != null && mCurrentFragment instanceof RowsFragment) {
((RowsFragment) mCurrentFragment).setExpand(true);
}
}
and same goes for the BrowseSupportFragment
as well
private void showHeaders(boolean show) {
if (DEBUG) Log.v(TAG, "showHeaders " + show);
mHeadersSupportFragment.setHeadersEnabled(show);
setHeadersOnScreen(show);
setRowsAlignedLeft(!show);
if (mRowsSupportFragment != null) {
mRowsSupportFragment.setExpand(true);
} else if (mCurrentFragment != null && mCurrentFragment instanceof RowsSupportFragment) {
((RowsSupportFragment) mCurrentFragment).setExpand(true);
}
}
来源:https://stackoverflow.com/questions/35151717/how-to-always-show-headers-in-rowsfragment