I'm trying to make a BottomSheetDialog inside my MainActivity, but right now I'm using synthetic to bind my views. But now I'm stuck with how to attach ViewBinding
to my BottomSheetDialog
.
Here's what I do, using synthetic.
dialog = BottomSheetDialog(this, R.style.BottomDialogStyle)
dialogView = LayoutInflater.from(this).inflate(R.layout.test_dialog, dialog.mainContainer, false)
dialog.setContentView(dialogView)
And here is what's confusing me with ViewBinding
dialog = BottomSheetDialog(this, R.style.BottomDialogStyle)
binding = TestDialogBinding.inflate(?)
dialog.setContentView(binding.root)
From my example above, I'm wondering what I should fill the parameters with, because unlike in an activity where I could just fill that parameter with layoutInflater
or in a RecyclerView
Adapter where I cant fill that parameter with
LayoutInflater.from(parent.context), parent, and false
.
It is possible to use databinding in a Dialog, first to get the binding working on your Dialog you should inflate it first and pass it to the setContentView like this. DialogOlaBookingConfirmedBinding binding = DataBindingUtil. inflate(LayoutInflater. from(getContext()), R.
↳ com.google.android.material.bottomsheet.BottomSheetDialogFragment. Modal bottom sheet. This is a version of DialogFragment that shows a bottom sheet using BottomSheetDialog instead of a floating dialog.
You also can create a LayouInflater :
val inflater = LayoutInflater.from(requireContext())
then pass inflater to :
binding = TestDialogBinding.inflate(inflater)
For Binding follow as mentioned :
bottomSheetDialog = BottomSheetDialog(mContext, R.style.BottomSheetDialogStyle)
mBottomSheetBinding = TestDialogBinding.inflate(layoutInflater, null, false)
bottomSheetDialog.setContentView(mBottomSheetBinding!!.root)
bottomSheetDialog.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With