我们如何从布局中删除动态添加的片段 [英] How we can Remove Dynamically added Fragments from layout
本文介绍了我们如何从布局中删除动态添加的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我.我有一个片段说FRAGMENT A并正在动态地将其添加到布局中...假设我已经向该layout中添加了FRAGMENT A的3个实例.然后我如何以编程方式删除该3个Fragment实例.我尝试了google搜索以及另一个stackoverflow线程,但是它们不起作用..
Can any one help me. I have a Fragment say FRAGMENT A and am adding it to a layout dynamically...Suppose i have added 3 instance of FRAGMENT A to that layout.Then How i can Remove that 3 Fragment instance programmatically.I tried google searches and also another stackoverflow threads but they are not working..
请帮帮我
谢谢
推荐答案
实际上非常简单:
假设您添加了这样的片段:
let's say you added the fragment like this:
fragmentTransac.add(R.id.content, fragA);
相反,您也将其添加有TAG
instead, you'll add it with a TAG too
fragmentTransac.add(R.id.content, new FragA(), "first");
// then the other
fragmentTransac.add(R.id.content, new FragA(), "second");
然后删除:
Fragment f = getFragmentManager().findFragmentByTag("first");
if(f!=null) fragmentTransac.remove(f);
fragmentTransac.commit();
快乐编码=]
这篇关于我们如何从布局中删除动态添加的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文