Android Data Binding two way binding with array

天涯浪子 提交于 2020-01-05 07:39:09

问题


I want to achieve two-way binding on a array with Data Binding in Android.

This is a simplified version of the code I have:

<data>
    <variable
        name="values"
        type="Integer[]" />
</data>

<EditText
    ...
    android:text="@={Converter.toString(values[0])} />

But when I try to build this code I get a message as follows:

cannot find method setTo(java.lang.Integer[], int, java.lang.Integer) in class android.databinding.ViewDataBinding

How can I achieve two-way binding with an array, if at all possible?


回答1:


How about trying the following way by using ArrayList.

<data>
    <import type="java.util.ArrayList"/>
    <variable
        name="values"
        type="ArrayList&lt;Integer&gt;"/>
</data>

<EditText
    ...
    android:text="@={Converter.toString(values.get(0))} />


来源:https://stackoverflow.com/questions/47058632/android-data-binding-two-way-binding-with-array

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