Bottom sheet not inflating in activity

I have this bottom sheet that i wanted to inflate on button click in my DialogsActivity.java but whenever i run my app and click the button nothing happens.

this is the code where it should've inflated the bottom sheet.

DialogsActivity.java

    floatingButtonContainer = new FrameLayout(context);
            floatingButtonContainer.setVisibility(onlySelect && initialDialogsType != 10 || folderId != 0 ? View.GONE : View.VISIBLE);
            contentView.addView(floatingButtonContainer, LayoutHelper.createFrame((Build.VERSION.SDK_INT >= 21 ? 56 : 60) + 20, (Build.VERSION.SDK_INT >= 21 ? 56 : 60) + 20, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 4 : 0, 0, LocaleController.isRTL ? 0 : 4, 0));
            
     floatingButtonContainer.setOnClickListener(v -> {
                

                LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
                inflater.inflate(R.layout.fragment_bottom_sheet,null);
    
          
            });

This is the BottomSheetFrag.java

public class BottomSheetFrag extends BottomSheetDialogFragment {

    public BottomSheetFrag(){

    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
        //return super.onCreateView(inflater, container, savedInstanceState);
        return inflater.inflate(R.layout.fragment_bottom_sheet, container, false);
    }
}

Solution 1:

You BottomSheetFrag code looks fine.

You dont need to inflate BottomSheetFrag in activity, instead you should use Fragment Transaction for this purpose.

Please update your DialogActivity code as below.

    BottomSheetFrag bottomSheet = new BottomSheetFrag();

    FragmentManager fragmentManager = getSupportFragmentManager();

    fragmentManager.executePendingTransactions();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if (bottomSheet.isAdded()) {
        FragmentTransaction removeTransaction = fragmentManager.beginTransaction();
        removeTransaction.remove(bottomSheet);
        removeTransaction.commitNow();
    }

    fragmentTransaction.add(bottomSheet, "tag");
    fragmentTransaction.commitNow();