[英]How to use android data binding properly
I have the following XML with data binding: 我有以下具有数据绑定的XML:
<EditText
android:id="@+id/addvalue"
android:inputType="numberDecimal"
android:digits="0123456789,€"
android:text="0,00 €"/>
<Button
android:id="@+id/add"
android:onClick="@{() -> fragment.addManualPosition(addvalue.text)}"/>
I get the error 我得到错误
"data binding error ****msg:if getId is called on an expression, it should have an id: addvalue.text"
I can not find anything at all that would help me understand what this error is supposed to mean or how to fix it. 我根本找不到任何可以帮助我理解此错误的含义或解决方法的内容。
I found it myself. 我自己找到的。 However because there is absolutely nothing written about this error message and it being extremely misleading, I'll keep the question online.
但是,由于绝对没有关于该错误消息的记录,而且它极具误导性,因此我将在线上保持该问题。
Fix: The lambda is a perfectly fine Kotlin lambda. 修正:Lambda是完美的Kotlin Lambda。 However Data Binding seems to generate Java code.
但是,数据绑定似乎会生成Java代码。 So it must not be addvalue.text but addvalue.getText() .
因此,它一定不能是addvalue.text,而是addvalue.getText()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.