Android data binding attribute not found
Bind the variables using @{ }
activity_main.xml
</layout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".simple.MainActivity">
<include layout="@layout/content_main_data_binding"
bind:name="@{ "Hello World" }" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
content_view.xml
</layout>
<data>
<variable
name="name"
type="String" />
</data>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{ name }"/>
</layout>
GL
I think I've hit upon the solution. To activate data binding, you need to use a @{}
expression, and what's in the braces must be valid Java code. So a literal string must be enclosed in quotes... which must be encoded as "
inside an XML attribute value. Put it all together and you get:
<include
layout="@layout/custom_edit_text"
app:hint123="@{"Email"}"/>
Data binding does work for include files, it's just that the syntax for a literal is a bit convoluted. I had the same issue and this form is working in my project.