Android 侦听器绑定 (XML) 未执行

Android listener bindings (XML) are not executed

我有一个带有以下 ViewHolder class 的自定义 RecyclerAdapter,它将两个变量绑定到视图:

inner class ViewHolder(private val binding: ViewDataBinding) :
    RecyclerView.ViewHolder(binding.root) {
    fun bind(obj: Any) {
        binding.setVariable(BR.viewHolder, this)
        binding.setVariable(BR.obj, obj)
        binding.executePendingBindings()
    }

    fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
        Log.i("test", "Change is here!")
    }

    fun onTextClicked() {
        Log.i("test", "Click is here!")
    }
}

和这个对应的(最小)视图:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

    <variable
        name="holder"
        type="(...).adapters.ContactPropertyRecyclerAdapter.ViewHolder" />

    <variable
        name="obj"
        type="(...).models.Address" />
</data>

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <EditText
        android:id="@+id/streetEditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="16dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="@{obj.street}"
        android:onTextChanged="@{(s, start, before, count) -> holder.onTextChanged(s, start, before, count)}"
        android:onClick="@{() -> holder.onTextClicked()}"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</layout>

这两个功能似乎都没有被触发,我从日志中可以看出。没有抛出错误。 AndroidStudio 正在识别这两个函数的用法。

obj 变量似乎工作正常,我已经尝试使用额外的 class,结果相同。

您正在设置变量 viewHolder

binding.setVariable(BR.viewHolder, this)

而您只定义了一个 holder 变量。

因此 holder 总是 null