【发布时间】:2021-08-10 16:39:34
【问题描述】:
我遇到了复杂数据绑定的问题。
当我使用带有 1 个参数的自定义绑定适配器时,它可以正常工作:
@BindingAdapter(value = ["myText"])
fun myBindingFun(
view: View,
myText: String?
) { ... }
myText="@{property.text}" <-- where text is an ObservableField<String>
但是,只要我添加第二个 args(需要 arg:"%s property" 的字符串 res),编译就会失败...
@BindingAdapter(value = ["myText", "resourceId"])
fun myBindingFun(
view: View,
myText: String?,
@StringRes resourceId: Int,
) { ... }
Cannot find a setter for ... that accepts parameter type 'androidx.databinding.ObservableField<java.lang.String>'
If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.
当我添加第二个参数时,我只需将 resourceId 属性添加到我的 XML 中:
myText="@{property.text}"
resourceId="@{@{string/my_string}}"
我也试过
myText="@{property.text}"
resourceId="@string/my_string"
你有没有遇到过这个问题?
谢谢!
【问题讨论】:
标签: kotlin data-binding