我正在尝试为扩展了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,它将起作用。
有没有办法使这种泛型?