Previous fragment visible under the new fragment

后端 未结 7 1403
心在旅途
心在旅途 2021-02-05 04:10

I have a tab + ViewPager layout and in one of these tabs I have a list view. When I replace that list fragment upon the onclick I can still see the old fragment u

7条回答
  •  故里飘歌
    2021-02-05 04:28

    Best code for it. clearly and not used another ram of device. on you Activity onCreate or before adding fragments add this code:

    for (Fragment fragment : getSupportFragmentManager().getFragments()) {
        if (fragment instanceof NavigationDrawerFragment) {
            continue;
        }
        else if (fragment != null) {
            getSupportFragmentManager().beginTransaction().remove(fragment).commit();
        }
    }
    

    Happy coding :)

提交回复
热议问题