Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 939
user3750186 Avatar asked Aug 03 '18 18:08

user3750186


1 Answers

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

like image 121
user3750186 Avatar answered Oct 02 '22 18:10

user3750186