找不到值为类型Boolean的属性“app:vm”的GETTER [英] Cannot find the GETTER for attribute 'app:vm' with value type Boolean

查看:214
本文介绍了找不到值为类型Boolean的属性“app:vm”的GETTER的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在自定义控件中使用原生的双向android数据绑定

I'm trying to use native 2-way android data binding in my custom control

所以我在xml中有这样的东西

so I have something like that in xml

<layout>
<data>
<variable name="item" type="Boolean"/>
</data>
...
<my.control app:vm="@={item}"/>
...
</layout>






请注意,关于 code> @ = {} - 原生2路绑定。


Please note, it's question about @={} - native 2 way binding.

和类似的代码:

class MyControl extends RelativeLayout{
...
@BindingAdapter("app:vm")
public static void setVm(View v, VM vm){...}
}

我的问题 - 我应该如何为我的viewModel定义getter?我没有找到任何指导。我尝试了不同的方法 - 编写自定义getter,静态getter,但错误仍然是一样的。

My questions - how should I define getter for my viewModel? I don't find any guidance about it. I tryed different approaches - write custom getter, static getters but error still the same.

推荐答案

取自这里,在滚动自己的下:

Taken from here, under "Rolling Your Own":

您需要一些额外的代码才能使用自定义类来实现双向数据绑定。最重要的是,您需要定义一个 @InverseBindingMethod

You'll need a little more extra code to get the two-way databinding working with custom classes. Most importantly, you'll need to define a @InverseBindingMethod:

@InverseBindingMethods({
   @InverseBindingMethod(type = MyControl.class, attribute = "vm"),
})




在这种情况下,getter的名称与app:vm的属性getVm的名称相匹配(更改为您的示例)

In this case, the name of the getter matches the name of the attribute "getVm" for "app:vm." (Changed to your example)

请访问链接的博客 - 它有更多关于该主题的信息,包括绑定属性更改的事件监听器。

Please visit the linked blog- it has more information on that topic, including the binding of a attribute changed event listener.

这篇关于找不到值为类型Boolean的属性“app:vm”的GETTER的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆