Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?!

like image 511
Hussien Fahmy Avatar asked Jun 21 '26 21:06

Hussien Fahmy


1 Answers

I also faced similar type of problem as mentioned in title. I was trying to change the visibility via data binding for <include> tag layout, like this:

<include
            android:id="@+id/viewNoData"
            layout="@layout/layout_no_data"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/quickActionRv"
            android:visibility="@{case== Case.NoData? View.VISIBLE : View.GONE}
            />

The solution was that I had to wrap my sublayout layout_no_data with

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

    </data>
Your content layout
</layout>

Hope it will help someone.

like image 56
master Gaurav Avatar answered Jun 23 '26 11:06

master Gaurav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!