Context in Android Databinding XML files

It is so easy guys, just don’t forget that DataBinding creates a field called context which you can access by default in your XML file. So you can write something like this:

 

<data>
   <variable name="name" type="String"/>
</data>
<layout>
  <TextView
      app:text="@{StringUtils.format(context, name)}" />
</layout>

And it will be just fine. You have the context from the parent view. Check it HERE.

You may also like...