【发布时间】:2013-08-26 13:24:42
【问题描述】:
嗨朋友们,我在movies.xml中有两个框架布局,即container,detail_screen。在容器中将添加包含listview的movies.xml,并且在 detail_screen 中将有一个名为 movie_details.xml 的可扩展列表视图。现在想以编程方式检查 detail_screen 是否已经呈现片段。如果呈现只是想删除该片段。我通过以下方式完成了它的工作正常。
if (getSupportFragmentManager().findFragmentByTag("MyFragment") != null) {
getSupportFragmentManager().beginTransaction().remove(getSupportFragmentManager().findFragmentByTag("MyFragment")).commit();
}
但是有没有其他方法可以通过编程方式在 android 的框架布局中查找片段是否存在。在此先感谢
【问题讨论】:
-
不使用 findFragmentByTag()/Id
-
您想知道片段是否存在,但没有对其或其容器的引用?
getSupportFragmentManager().getFragments()检索该管理器的片段列表。 -
@kmg 我想检查我的框架布局中是否已经存在片段只是想删除该片段添加新片段,否则将多次添加相同的片段
-
如果您使用
getSupportFragmentManager().beginTransaction().replace(),它将替换或添加 - 您不必担心删除现有片段 -
@sugan.s replace() 不适合您的情况?
标签: android fragment android-framelayout