Android Data Binding @BindingConversion failure for int to string
Beware, In latest DataBinding
(2019), It does NOT require importing Integer
nor String
or you will get this error:
****/ data binding error ****msg:Missing import expression although it is registered file
official doc says : java.lang.* is imported automatically.
Just go either
android:text="@{Integer.toString(myViewModel.number)}"
or
android:text="@{String.valueOf(myViewModel.number)}"
directly.
android:text
with an int
assumes that the int
is a string resource ID. Use android:text="@{Integer.toString(myViewModel.number)}"
.
You will also need to import the (no longer needed)Integer
class: