0

从我打开 VideoPlayerFragment 的主片段开始,在 VideoPlayerFragment 中,当我按下按钮时,它应该返回到父片段。

CollectionDemoActivity{

class LaunchpadSectionFragment extends ListFragments{

public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

String fragMainGroups = "mainGroups";


                    Fragment fragment1 = new VideoPlayerFragment();

                    FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
                    transaction.replace(R.id.contentFragment, fragment1, fragMainGroups );
                    transaction.addToBackStack(fragMainGroups);
                    transaction.commit(); 

      }
   }
}

外部类

VideoPlayerFragment.java

类 VideoPlayerFragment 扩展 ListFragment{

            @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                    Bundle savedInstanceState) {

                            String Groups = "Groups";

                            Fragment fragment1 = new CollectionDemoActivity.LaunchpadSectionFragment();

                            FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
                            transaction.replace(R.layout.load_main_groups_activty, fragment1, Groups);
                            transaction.addToBackStack(Groups);
                            transaction.commit(); 

             }

}

4

1 回答 1

0

我必须使用下面的代码来使用它的片段标签从后台打开前一个片段。

String fragMainGroups = "mainGroups";
                            String Groups = "Groups";

                            Fragment fragment = (Fragment) getFragmentManager().findFragmentByTag(fragMainGroups);                                              


                            if (fragment != null) // could be null if not instantiated yet
                            {
                                if (fragment.getView() != null) {
                                    // Pop the backstack on the ChildManager if there is any. If not, close this activity as normal.
                                    if (!fragment.getFragmentManager().popBackStackImmediate()) {
                                        fragment.getFragmentManager().popBackStack();
                                        //getActivity().finish();
                                    }
                                }
                            }
于 2013-08-02T02:46:24.133 回答