检查片段是否显示在framelayout中或不在android中? [英] Check fragment is presented in framelayout or not in android?

查看:192
本文介绍了检查片段是否显示在framelayout中或不在android中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,我在movie.xml中有两个frameLayout,分别是 container detail_screen .在容器中将添加 movies.xml ,其中包含listview,然后在detail_screen中将有一个名为 movie_details.xml 的可扩展列表视图.现在要以编程方式检查detail_screen中是否已显示片段.如果显示,则只想删除该片段.

Hi friends I have two framelayout in movies.xml namely container, detail_screen.In container will add movies.xml which contains listview ,and in detail_screen will have expandable listview called movie_details.xml.Now want to check programatically in detail_screen is already fragment presented or not.if presented just want remove that fragment.I did by follwing and its working fine.

    if (getSupportFragmentManager().findFragmentByTag("MyFragment") != null) {
        getSupportFragmentManager().beginTransaction().remove(getSupportFragmentManager().findFragmentByTag("MyFragment")).commit();
}

但是还有其他方法可以通过编程方式来查找片段是否在android的帧布局中呈现.谢谢

but is there any other way to find whether fragment is presented or not in frame layout in android by programatically .Thanks in advance

推荐答案

我按照以下方法创建了解决方案.即,在将任何片段添加到details_screen之前,仅检查是否已存在片段,然后将其弹出,然后将其添加为新片段./p>

I founded the solution as follows.i.e before adding any fragments to details_screen just checking if already fragment is presented then popping it and then will add the new fragment.

if (getSupportFragmentManager().findFragmentById(R.id.detail_screen) != null) {

        getSupportFragmentManager().popBackStack();

            } //to do add fragment

希望它能工作.

这篇关于检查片段是否显示在framelayout中或不在android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆