我正在尝试对具有自定义视图的自定义视图使用双向数据绑定。
这是我现在拥有的:
@BindingAdapter("setValue")
fun setTextValue(comboField: ComboboxField, value: String?) {
if (value != comboField.value.text.toString()) comboField.value.setText(value)
}
@InverseBindingAdapter(attribute = "setValue", event = "setValueAttrChanged")
fun getTextValue(comboField: ComboboxField): String? {
return comboField.value.text.toString()
}
@InverseBindingMethods(InverseBindingMethod(type = ComboInputBinding::class, attribute = "c", event = "setValueAttrChanged"))
class ComboInputBinding {
@BindingAdapter("setValueAttrChanged")
fun setListener(comboField: ComboboxField, listener: InverseBindingListener) {
comboField.value.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {
listener.onChange()
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
})
}
}
上课是我的自定义视图。
<common.component.ComboboxField
android:id="@+id/orgaos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:setValue="@={viewModel.mutableStringLiveData}"
app:hint="@string/emission_orgao" />
但是我得到了
java.lang.String callbackArg_0 = mBindingComponent.null.getTextValue(orgaos);
我想念什么吗?