将片段添加到最顶层/显示片段后面的backstack中

时间:2014-11-03 08:44:38

标签: android android-fragments

我想知道是否有一种方法可以将片段添加到显示片段后面的backstack中。因此,当用户按下“后退按钮”时,添加的片段将显示给用户。

1 个答案:

答案 0 :(得分:0)

根据我的知识,我不确定Fragment Manager可以做这些事情!

将片段安装到容器时

Step-1 Why don't you add the fragment to backStack`

第2步:下一个onBackpressedclick of any view只是从容器中弹出片段


<强> Here is a sample from another Stackoverflow answer

fragmentTransaction.addToBackStack("fragB");
fragmentTransaction.addToBackStack("fragC");
Then in Fragment_C, pop the back stack using the name ie.. fragB and include POP_BACK_STACK_INCLUSIVE

    someButtonInC.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            FragmentManager fm = getActivity()
                    .getSupportFragmentManager();
            fm.popBackStack ("fragB", FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
    });