Check fragment is presented in framelayout or not in android?

♀尐吖头ヾ 提交于 2019-12-05 08:02:04

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

hope it will work.

You have to use findFragmentByTag() or findFragmentById() methods to find it. If returned instance is not null, then the fragment is present. Additionally you can use Fragment.isInLayout() method to check whether fragment was defined in layout using <fragment> tag or added programmatically.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!