片段越来越重叠在后退按钮 [英] Fragments are getting overlapped on back button
问题描述
我已经创建了3个片段,即(碎裂,FragmentB,FragmentC)和一个MainActivity。 有一个在每个片段取代自己与下一个片段,直到FragmentC一个按钮。
I have created 3 Fragments namely (FragmentA, FragmentB, FragmentC) and one MainActivity. There is a button in each fragment which replaces itself with next Fragment till FragmentC.
我更换碎裂(含)FragmentB(然后)FragmentC。
I am replacing FragmentA (with) FragmentB (then with) FragmentC.
交易从碎裂到FragmentB使用以下功能
Transaction from FragmentA to FragmentB uses below function
@Override
public void fragmentreplacewithbackstack(Fragment fragment, String tag) {
FragmentManager fragmentManager=getSupportFragmentManager();
FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.contner,fragment , tag);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
// fragmentManager.executePendingTransactions();
}
交易从FragmentB到FragmentC使用以下功能
Transaction from FragmentB to FragmentC uses below function
public void fragmentreplace(Fragment fragment,String tag){
FragmentManager fragmentManager=getSupportFragmentManager();
FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.contner,fragment , tag);
fragmentTransaction.commit();
}
问题是,当我preSS后退按钮从FragmentC,FragmentC和碎裂相互重叠。
problem is when i press back button from FragmentC, FragmentC and FragmentA overlap with each other.
推荐答案
您需要添加C片段,如果你想从这里去片段B背面preSS以backstack为好。
You need to add Fragment C to backstack as well if you wanna go to Fragment B on back press from here.
于是拨打下面的C片段为好。
So call the below for Fragment C as well.
fragmentTransaction.addToBackStack(null);
编辑 - 改变你正在使用从B到C走这电流法,
EDIT - Change this current method you are using to go from B to C,
public void fragmentreplace(Fragment fragment,String tag){
FragmentManager fragmentManager=getSupportFragmentManager();
FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.contner,fragment , tag);
fragmentTransaction.addToBackStack(null); //this will add it to back stack
fragmentTransaction.commit();
}
这篇关于片段越来越重叠在后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!