Java 类android.support.v17.leanback.widget.OnChildSelectedListener 实例源码

项目:BuildingForAndroidTV    文件:CustomHeadersFragment.java   
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    customSetBackground(R.color.fastlane_background);
    setHeaderAdapter();

    setCustomPadding();

    /**
     * The setOnItemSelectedListener has been not only deprecated, but brutally removed by
     * Google. To get around this limitation, I went to see how BaseRowFragment handled it.
     * Turns out it sets a listener to the GridView (which is a RecyclerView): there you go.
     */
    VerticalGridView gridView = ((MainActivity) getActivity()).getVerticalGridView(this);
    gridView.setOnChildSelectedListener(new OnChildSelectedListener() {
        @Override
        public void onChildSelected(ViewGroup viewGroup, View view, int i, long l) {
            Object obj = ((ListRow) getAdapter().get(i)).getAdapter().get(0);
            getFragmentManager().beginTransaction().replace(R.id.rows_container, (Fragment) obj).commit();
            ((MainActivity) getActivity()).updateCurrentFragment((Fragment) obj);
        }
    });

}