Android DataBinding where to get context?

bakua picture bakua · Sep 3, 2015 · Viewed 17.5k times · Source

I have TextView for showing time. I want to use Android's DataBinding plugin.

For formatting time I am using DateUtils.formatDateTime(context, int, int) method which takes Context instance. Is it possible to get context include element? Or do I have to use old school way?

Thanks

Answer

epool picture epool · Jan 25, 2016

Also you can do something like this in your view using the current view context as parameter.

...
android:text="@{yourModelHere.yourModelMethodHere(context)}"
...