Search code examples
kotlinandroid-binding-adapter

Parameter not found using binding adapter


When I try to put a second parameter "imgError" in my BindingAdapter I have an error.

This is my BindingAdapter :

@BindingAdapter("imageUrl", "imgError", requireAll = true)
fun loadImage(view: ImageView, imageUrl: String?, imgError: Drawable) {
    if (!imageUrl.isNullOrEmpty())
        Picasso.get().load(imageUrl).error(imgError).into(view)
    else
        view.setImageDrawable(imgError)
}

I have this error :

AAPT: error: attribute imgError not found

I try differents way to solve it but nothing work.

This i how I use it :

<com.google.android.material.imageview.ShapeableImageView
                android:id="@+id/shapeableImageView"
                android:layout_width="75dp"
                android:layout_height="75dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:shapeAppearanceOverlay="@style/ShapeCorner"
                app:imageUrl="@{profile.photo.url}"
                app:imgError="@drawable/ic_placeholder_user_photo"
                tools:srcCompat="@drawable/ic_placeholder_user_photo"/>

Solution

  • My error was setting my drawable without using databinding:

    app:imgError="@{@drawable/ic_placeholder_user_photo}"