安卓应用在使用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()。

相关内容

热门资讯

2026版方法!we-poke... 2026版方法!we-poker正规吗,智星菠萝透视,确实确实有挂(竟然有挂)1、智星菠萝透视辅助器...
今日重大通报!德州私人局脚本,... 今日重大通报!德州私人局脚本,aa poker辅助,切实是真的有挂(有挂技巧)1、辅助软件下载优化,...
刚刚!wepoker免费透视,... 刚刚!wepoker免费透视,德扑软件,切实确实有挂(有挂方式)在进入德扑软件软件靠谱后,参与本局比...
我来教教你!约局吧作弊脚本,智... 我来教教你!约局吧作弊脚本,智星德州有脚本吗,果然真的有挂(有挂功能)1、免费脚本咨询教程、免费脚本...
现有关情况通报如下!wepok... 现有关情况通报如下!wepoker如何设置透视,德扑之星怎么设置埋牌,好像存在有挂(有挂总结)1、金...
揭秘攻略!wpk辅助是什么,a... 揭秘攻略!wpk辅助是什么,aapoker脚本怎么用,果然有挂(有挂教学)辅助器是一种具有地方特色的...
技巧辅助挂!wepoker游戏... 技巧辅助挂!wepoker游戏的安装教程,德扑之星辅助工具如何打开,本来真的是有挂(有挂秘诀)德扑之...
分享实测!wepoker挂,h... 分享实测!wepoker挂,hhpoker辅助,一贯是有挂(确实有挂)1)有没有挂:进一步探索有辅助...
近期!wepoker私局辅助,... 近期!wepoker私局辅助,德普之星怎么开辅助,本来存在有挂(有挂方法)1、德普之星怎么开辅助免费...
玩家必知教程!wepoker辅... 玩家必知教程!wepoker辅助是真的吗,hhpoker是内部控制吗,竟然真的是有挂(有挂方略)1、...