I am having trouble in implementing view binding in a Custom Dialog Layout. Is it possible?
 private fun showCustomDialog(title: String) {
    val dialog = Dialog(activity)
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
    dialog.setCancelable(false)
    dialog.setContentView(R.layout.custom_layout)
    val body = dialog.findViewById(R.id.body) as TextView
    body.text = title
    val noBtn = dialog.findViewById(R.id.noBtn) as TextView
    yesBtn.setOnClickListener {
        dialog.dismiss()
    }
    val yesBtn = dialog.findViewById(R.id.yesBtn) as Button
    noBtn.setOnClickListener { dialog.dismiss() }
    dialog.show()
}
                It is possible.
CustomDialogBinding binding = CustomDialogBinding 
          .inflate(LayoutInflater.from(getContext()));
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setView(binding.getRoot());
Where CustomDialogBinding is the name of the view binding file for your custom layout
kotlin
val bind :CustomDialogBinding = CustomDialogBinding .inflate(inflater)
dialog.setContentView(bind.root)
                        Code:
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val binding = CustomDialogLayoutBinding.inflate(inflater)
dialog.setContentView(binding.root)
                        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