安卓应用在使用AndroidStudiogetSupportFragment.beginTransaction().replace时切换到另一个Fragment时出现崩溃(Java)。
创始人
2024-11-09 19:30:38
0次

可能是由于FragmentManager在切换Fragment的过程中出现问题所致,我们可以尝试将FragmentManager改为ChildFragmentManager。

以下是可能的代码示例:

在主Fragment中:

ChildFragment childFragment = new ChildFragment();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.replace(R.id.child_fragment_container, childFragment);
transaction.addToBackStack(null);
transaction.commit();

在子Fragment中:

ParentFragment parentFragment = new ParentFragment();
FragmentTransaction transaction = getParentFragmentManager().beginTransaction();
transaction.replace(R.id.parent_fragment_container, parentFragment);
transaction.addToBackStack(null);
transaction.commit();

这种方法在处理具有嵌套Fragment时通常比FragmentManager更好用。注意,如果使用的是androidx.fragment.app.Fragment,则需要使用getChildFragmentManager()和getParentFragmentManager()来代替getFragmentManager()。

相关内容

热门资讯

WPK四人法子!红龙poker... WPK四人法子!红龙poker透视工具,德州微扑克好像是有辅助器技巧1、完成红龙poker透视工具有...
WPK俱乐部妙招!aapoke... WPK俱乐部妙招!aapoker可以开挂吗,德州微扑克好像存在有透视挂教程aapoker可以开挂吗透...
WPK作弊妙计!wepoker... WPK作弊妙计!wepoker破解游戏盒子,德州微扑克本来真的是有透视app小薇(辅助器软件下载)致...
WPK真假法门!aapoker... WPK真假法门!aapoker透视脚本安装包,德州微扑克竟然存在有开挂技巧aapoker透视脚本安装...
WPK辅助器绝活儿!wepok... WPK辅助器绝活儿!wepoker有透视底牌吗,德州微扑克一贯有开挂工具1、wepoker有透视底牌...
WPK私人局法子!wepoke... WPK私人局法子!wepoker软件靠谱么,德州微扑克好像是真的有透视挂插件进入游戏-大厅左侧-新手...
WPK方法课程!wepoker... WPK方法课程!wepoker透视脚本苹果,德州微扑克真是有辅助器脚本1、在wepoker透视脚本苹...
WPK私人局学习!wepoke... 您好,wepoker私人局俱乐部辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704...
WPK工具方案!wepoker... WPK工具方案!wepoker免费透视脚本,德州微扑克果然是有开挂技巧1、wepoker免费透视脚本...
WPK德州局策略!wepoke... 您好,wepoker有辅助工具吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【13670430...