Android:自定义绑定适配器,视图可扩展并实现

时间:2019-07-06 19:20:02

标签: android android-databinding android-binding-adapter

我正在尝试为扩展了View并实现Checkable的通用视图构建自定义绑定适配器。 RadioButton是一个示例,但我想使其具有通用性,以便它可与其他可检查的视图一起使用。

如果我使用RadioButton,它确实起作用,但是,如果我使用<T> where T: View, T: Checkable,编译器将失败,并显示以下错误:data binding error ****msg:Cannot find the setter for attribute 'bind:checked' with parameter type

这是我失败的尝试:

@BindingAdapter("bind:checked")
fun <T> setChecked(view: T, customClass: CustomClass) where T: View, T: Checkable {
    view.isChecked = blah
}

如果我使用RadioButton而不是T,它将起作用。

有没有办法使这种泛型?

0 个答案:

没有答案