Search code examples
arraysandroid-databindingtwo-way-binding

Android Data Binding two way binding with array


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?


Solution

  • 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))} />