BindingAdapter With a List

235 Views Asked by At

I want to use a BindingAdapter with a List argument, but when I try to compile it, it throws this error,

Cannot find a setter for <androidx.cardview.widget.CardView app:setVisiblityByList> that accepts parameter type 'java.util.List<Alert>'

My method:

@BindingAdapter("setVisibilityByList")
fun setVisibilityByList(view: View, l: List<*>?) {
if (l?.isNotEmpty() == true) {
    view.visibility = View.VISIBLE
} else {
    view.visibility = View.GONE
}

}

My XML:

<androidx.cardview.widget.CardView
            android:id="@+id/card_view_alert"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_width="match_parent"
            android:visibility="gone"
            app:cardBackgroundColor="#77000000"
            app:cardCornerRadius="10dp"
            app:cardElevation="0dp"
            app:contentPadding="5dp"
            app:setVisiblityByList="@{locationAndWeather.alerts}">

I have also tried with fun setVisiblityByList(view: View, l: List<Alert>?) with the same result. It seems to be a problem caused by Java's type erasure. Is there any way to get this to work?

0

There are 0 best solutions below