androidkotlindata-bindingandroid-databindingandroid-binding-adapter

Android Databinding Cannot find a setter for * that accepts parameter type *


Am trying to declare a variable in databinding layout it's type is array of integer but I getting an error when building the project

Cannot find a setter for <android.widget.LinearLayout app:availableGradesIndexes> that accepts parameter type 'int[]'

If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.

the variable declaration in xml

<variable
    name="availableGradesIndexes"
    type="int[]" />

<variable
    name="subject"
    type="Subject" />

the binding adapter

@BindingAdapter("availableGradesIndexes", "subject")
fun LinearLayout.bindGradeWithMarks(availableGradesIndexes: Array<Int>) {
    //....
}

usage

<LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:subjct="@{subject}"
        app:availableGradesIndexes="@{availableGradesIndexes}"
        tools:layout_height="@dimen/_40sdp" />

What else I Tried

tried to declare the type of binding adapter method to IntArray like fun LinearLayout.bindGradeWithMarks(availableGradesIndexes: IntArray)

also tried a List<Int> like fun LinearLayout.bindGradeWithMarks(availableGradesIndexes: List<Int>) and variable type List&lt;Int&gt;

also tried the binding variable type to be Integer and Integer[] and also List&lt;Integer&gt;

so the question is how to bind a list or array of integer with binding adapter ?!


Solution

  • The problem was in another attribute name and I don't know why the error message didn't mention it !!

    <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:subjct="@{subject}" //the attribute name was messing a letter (subject)
            app:availableGradesIndexes="@{availableGradesIndexes}"
            tools:layout_height="@dimen/_40sdp" />