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.
public void showBottomSheetDialogFragment() {
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:
Baca Juga
- Getactivity Return Null In Fragment Onactivitycreated In Some Rooted Device
- Android Kotlin Get Data From A Clicked Item In Recyclerview And Pass It Between Fragments
- Cannot Access 'androidx.lifecycle.hasdefaultviewmodelproviderfactory' Which Is A Supertype Of 'favoritebottomdialogfragment'. Check Your Module Cla
Call this method on botton Click:
callToGuideShareDialog();
Inflate the bottom Sheet View inside this method
private void callToGuideShareDialog() {
final View viewBottom = DataBindingUtil.inflate(getLayoutInflater(), R.layout.------, null, false).getRoot();
ImageView imageView = viewBottom.findViewById(R.id.img_size_guide_share);
TextView textViewMsg = viewBottom.findViewById(R.id.----);
viewBottom.findViewById(R.id.-----).setOnClickListener(this);
TextView textViewMeasurement = viewBottom.findViewById(R.id.----);
sheetDialog = new BottomSheetDialog(context);
sheetDialog.setContentView(viewBottom);
viewBottom.post(new Runnable() {
@Override
public void run() {
BottomSheetBehavior mBehavior = 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"