Last active
July 1, 2024 11:22
-
-
Save elsennov/302cb7ec53bd0406ad03 to your computer and use it in GitHub Desktop.
Remove all child fragments inside parent fragment (Nested fragment)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void removeAllChildFragments() { | |
List<String> childFragmentTags = CHILD_FRAGMENT_TAGS_MAP.get(mParentId); | |
if (childFragmentTags != null && !childFragmentTags.isEmpty()) { | |
List<Fragment> childFragments = getChildFragmentManager().getFragments(); | |
if (childFragments != null && !childFragments.isEmpty()) { | |
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction(); | |
for (Fragment childFragment : childFragments) { | |
if (childFragment != null) { | |
if (childFragmentTags.contains(childFragment.getTag())) { | |
fragmentTransaction.remove(childFragment); | |
} | |
} | |
} | |
fragmentTransaction.commitAllowingStateLoss(); | |
childFragmentTags.clear(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment