Skip to content

Instantly share code, notes, and snippets.

@flashfoxter
Forked from elsennov/removeAllChildFragments
Created April 17, 2018 15:28
Show Gist options
  • Save flashfoxter/4422b3eb686ba85862cfdba943e2be0c to your computer and use it in GitHub Desktop.
Save flashfoxter/4422b3eb686ba85862cfdba943e2be0c to your computer and use it in GitHub Desktop.
Remove all child fragments inside parent fragment (Nested fragment)
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