Difference between @{} and @={} in android xml file?

505 Views Asked by At

"Form data in android xml example"

<TextView android:text="@{viewmodel.name}"/> <TextView android:text="@={viewmodel.name}"/>

2

There are 2 best solutions below

0
On BEST ANSWER

android:text="@{viewmodel.name}" is the syntax for 1-way binding

android:text="@={viewmodel.name}" is the syntax for 2-way binding

while the first is read-only, the 2nd allows you to update the value of the field in your viewmodel

0
On

you can use @={} for two way data binding in attributes like onClick or onChangeText ,... of your views in xml file and can't use that in Text or Color Attributes. but you can use @{} for one way data binding in Text or Color attributes. because 2 way data binding means when user change the view with his action in app and we want to change our data in our repository or database with data binding.

summery

      @={} use for attributes like onClick or onChangeText and etc for 2 way data binding.
      @{}  use for attributes like Text, Color and etc for 1 way data binding.