使用图像视图在 PageRow 元素之间导航

Navigate between PageRow elements with image view

我想向 header 个元素添加图像。我按照 this 教程成功添加了图像。它使用 ListRow 元素并与 ListRow 完美配合。

但是,当我将 ListRow 元素更改为 PageRow 时,它不会在 header 之间导航。以下是一些重要的变化。可能是什么原因?

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();
        }

    }
}

view.setFocusable(true); 添加到扩展 RowHeaderPresenter 的 onCreateViewHolder

添加这两行

view.setFocusable(true);
view.setFocusableInTouchMode(true);

到扩展 RowHeaderPresenter 的 onCreateViewHolder