user3750186
user3750186

Reputation: 661

How to use android data binding properly

I have the following XML with data binding:

<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.

Upvotes: 11

Views: 1218

Answers (1)

user3750186
user3750186

Reputation: 661

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. However Data Binding seems to generate Java code. So it must not be addvalue.text but addvalue.getText() .

Upvotes: 45

Related Questions