Using a BindingAdapter with a string-array from the resources

≯℡__Kan透↙ 提交于 2019-12-05 01:33:29
Ravi Rupareliya

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!