Using a BindingAdapter with a string-array from the resources
you can get it by refering stringArray
instead of array
. Here is what i have done with recyclerView to get value from resources and it is working perfectly, it might help you also.
in string.xml
<string-array name="myItems">
<item>Item 1</item>
<item>Item 2</item>
<item>Item 3</item>
<item>Item 4</item>
<item>Item 5</item>
<item>Item 6</item>
</string-array>
in layout.xml
app:entries="@{@stringArray/fi}"
in your case it can be app:data="@{@stringArray/countries}"
or app:keys="@{@stringArray/iso_3166_2}"
.
and in binding method
@BindingAdapter({"entries"})
public static void entries(RecyclerView recyclerView, String[] array) {
//get all values in array[] variable.
}
refer this for more.