我想将图像添加到标题元素中。我按照this教程成功添加了图像。它使用ListRow
元素,与ListRow
完美配合。
但是,当我使用ListRow
更改PageRow
元素时,它不会在标题之间导航。以下是一些重要的变化。可能是什么原因?
IconHeaderItemPresenter.java
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object o) {
IconHeaderItem iconHeaderItem = (IconHeaderItem)((PageRow)o).getHeaderItem();
View rootView = viewHolder.view;
...
}
MainFragment.java
public void createRows(){
IconHeaderItem headerItem1 = new IconHeaderItem(1, getString(R.string.header_history), R.drawable.header_images);
PageRow pageRow1 = new PageRow(headerItem1);
mRowsAdapter.add(pageRow1);
IconHeaderItem headerItem2 = new IconHeaderItem(2, getString(R.string.header_recommendations), R.drawable.header_musics);
PageRow pageRow2 = new PageRow(headerItem2);
mRowsAdapter.add(pageRow2);
IconHeaderItem headerItem3 = new IconHeaderItem(3, getString(R.string.header_news), R.drawable.header_videos);
PageRow pageRow3 = new PageRow(headerItem3);
mRowsAdapter.add(pageRow3);
IconHeaderItem headerItem4 = new IconHeaderItem(4, getString(R.string.header_notifications), R.drawable.header_settings);
PageRow pageRow4 = new PageRow(headerItem4);
mRowsAdapter.add(pageRow4);
}
private static class PageRowFragmentFactory extends BrowseFragment.FragmentFactory {
private final BackgroundManager mBackgroundManager;
PageRowFragmentFactory(BackgroundManager backgroundManager) {
this.mBackgroundManager = backgroundManager;
}
@Override
public Fragment createFragment(Object rowObj) {
Row row = (Row)rowObj;
mBackgroundManager.setDrawable(null);
//id for news fragment
if (row.getHeaderItem().getId() == 3) {
return new SampleFragmentA();
} else {
return new SampleFragmentB();
}
}
}
答案 0 :(得分:2)
添加这两行
view.setFocusable(true);
view.setFocusableInTouchMode(true);
到扩展RowHeaderPresenter的onCreateViewHolder
答案 1 :(得分:0)
将{"kind": "person", "fullName": "John Doe", "age": 22, "gender": "Male", "citiesLived": [{ "place": "Seattle", "numberOfYears": 5}, {"place": "Stockholm", "numberOfYears": 6}]}
{"kind": "person", "fullName": "Jane Austen", "age": 24, "gender": "Female", "citiesLived": [{"place": "Los Angeles", "numberOfYears": 2}, {"place": "Tokyo", "numberOfYears": 2}]}
添加到扩展RowHeaderPresenter的onCreateViewHolder