问题
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<Integer>"/>
</data>
<EditText
...
android:text="@={Converter.toString(values.get(0))} />
来源:https://stackoverflow.com/questions/47058632/android-data-binding-two-way-binding-with-array