2

我正在尝试为扩展View和实现的通用视图构建自定义绑定适配器CheckableRadioButton是一个例子,但我想让它通用,以便它与其他可检查的视图一起使用。

如果我使用 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,它可以工作。

有没有办法使这个通用?

4

0 回答 0