我想知道是否有一种方法可以将片段添加到显示片段后面的backstack中。因此,当用户按下“后退按钮”时,添加的片段将显示给用户。
答案 0 :(得分:0)
根据我的知识,我不确定Fragment Manager
可以做这些事情!
Step-1 :Why don't you add the fragment to
backStack`
第2步:下一个onBackpressed
或click 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);
}
});