从片段管理器中删除旧片段 [英] Remove old Fragment from fragment manager
本文介绍了从片段管理器中删除旧片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试学习如何在 android 中使用 Fragment
s.当新的 fragment
在 android 中调用时,我试图删除旧的 fragment
.
I'm trying to learn how to use Fragment
s in android.
I'm trying to remove old fragment
when new fragment
is calling in android.
推荐答案
您需要找到现有 Fragment 的引用并使用以下代码删除该 Fragment.您需要使用一个标签 ex 添加/提交片段.TAG_FRAGMENT".
You need to find reference of existing Fragment and remove that fragment using below code. You need add/commit fragment using one tag ex. "TAG_FRAGMENT".
Fragment fragment = getSupportFragmentManager().findFragmentByTag(TAG_FRAGMENT);
if(fragment != null)
getSupportFragmentManager().beginTransaction().remove(fragment).commit();
就是这样.
这篇关于从片段管理器中删除旧片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文