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<Int>
also tried the binding variable type to be Integer
and Integer[]
and also List<Integer>
so the question is how to bind a list or array of integer with binding adapter ?!
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" />