将第二个演示者添加到ArrayObjectAdapter实例

时间:2018-07-23 16:25:28

标签: android android-tv leanback android-mvp presenter

我正在使用实现leanback库的Android TV应用中的自定义片段,而不是RowsFragment。自定义片段由FrameLayout中的两个大小相等的水平LinearLayouts(屏幕的上半部分和下半部分)组成。下部显示使用VerticalGridPresenter的纸牌网格。

我想要完成的是当用户在卡之间导航时更新屏幕上方的视图。我可以使用以下方法进行操作。但是,我想知道使用另一个演示者更新片段(屏幕)的上部是否是更好/更干净的方法。 (ActualShowInformationPresenter)如何将第二个演示者添加到ArrayObjectAdapter实例?那是正确的方法吗?预先感谢。

sendmail

...

private void gridOnItemSelected(int position) {
    if (position != mSelectedPosition) {
        mSelectedPosition = position;
        Channel c = (Channel) mAdapter.get(position);

        //ActualShowInformationPresenter actualShowInformationPresenter = new ActualShowInformationPresenter();

        Context context = getMainFragmentAdapter().getFragment().getContext();

        if (c.getProgramme()!= null)           
           tvActualShowTitle.setText(c.getProgramme().get(0).getTitle().get(0));
        }          
    }
}

...

private OnItemViewSelectedListener mOnItemViewSelectedListener = new OnItemViewSelectedListener() {
    @Override
    public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
        int position = mGridViewHolder.getGridView().getSelectedPosition();
        Log.v(TAG, "grid selected position " + position);
        gridOnItemSelected(position);
    }
};

...

public void setGridPresenter(VerticalGridPresenter gridPresenter) {
    if (gridPresenter == null) {
        throw new IllegalArgumentException("Grid presenter may not be null");
    }
    mGridPresenter = gridPresenter;
    mGridPresenter.setOnItemViewSelectedListener(mOnItemViewSelectedListener);
    if (mOnItemViewClickedListener != null) {
        mGridPresenter.setOnItemViewClickedListener(mOnItemViewClickedListener);
    }
}

0 个答案:

没有答案