Skip to content Skip to sidebar Skip to footer

Bottom Sheet Fragment Causes Error When Called The Second Time

I have a class BottomSheetFragment extends BottomSheetDialogFragment, which contains sub-fragments, and I call it from a fragment. The problem is that when I call it the second ti

Solution 1:

You are trying to open the same fragment. The current fragment should be dismissed. bottomSheetFragment.dismiss(); then bottomSheetFragment.show(getSupportFragmentManager(), tag)

And you can try to give a different tag to fragment.

publicvoidshowBottomSheetDialogFragment() {
       bottomSheetFragment = new BottomSheetFragment();
       bottomSheetFragment.show(getSupportFragmentManager(), bottomSheetFragment.getTag());
}

Edit :

This error occurs on Nested Fragments which has been defined in layout, try to remove your Fragment from XML Layout and replace it with a FrameLayout then instantiate your Fragment dynamically in code.

Solution 2:

You are calling fragment tag inside XML file of YourFragment, basically, it's a wrong way to add bottom sheet to fragment. Here is the way you can do it:

Call this method on botton Click:

callToGuideShareDialog();

Inflate the bottom Sheet View inside this method

privatevoidcallToGuideShareDialog() {
finalViewviewBottom= DataBindingUtil.inflate(getLayoutInflater(), R.layout.------, null, false).getRoot();
            ImageViewimageView= viewBottom.findViewById(R.id.img_size_guide_share);
            TextViewtextViewMsg= viewBottom.findViewById(R.id.----);
            viewBottom.findViewById(R.id.-----).setOnClickListener(this);
            TextViewtextViewMeasurement= viewBottom.findViewById(R.id.----);

        sheetDialog = newBottomSheetDialog(context);
        sheetDialog.setContentView(viewBottom);

        viewBottom.post(newRunnable() {
            @Overridepublicvoidrun() {
                BottomSheetBehaviormBehavior= BottomSheetBehavior.from((View) viewBottom.getParent());
                mBehavior.setPeekHeight(viewBottom.getHeight());
            }
        });

        if (sheetDialog != null)
            sheetDialog.show();
}

Post a Comment for "Bottom Sheet Fragment Causes Error When Called The Second Time"