androidbroadcast / ViewBindingPropertyDelegate

Make work with Android View Binding simpler
https://proandroiddev.com/make-android-view-binding-great-with-kotlin-b71dd9c87719
Apache License 2.0
1.42k stars 102 forks source link

Binding in an AlertDialog doesn't work #41

Closed cristan closed 3 years ago

cristan commented 3 years ago
class MyDialogFragment : DialogFragment() {
    private val binding: MyDialogBinding by dialogViewBinding(R.id.my_dialog_container)

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = 
        AlertDialog.Builder(requireContext())
            .setView(R.layout.my_dialog)
            .create()

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        binding.myButton.setOnClickListener { dismiss() }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_dialog_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/my_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Button!" />

</FrameLayout>

I don't get a crash anymore (I did in 1.2.2), but doing anything with the binding (like setting the onClickListener to the Button) has no effect.

kirich1409 commented 3 years ago

Will be fixed in 1.4.2