Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@BindingAdapter not working with Android Kotlin library

I've this BindingAdapter to load image using Glide in my library module

import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide

@BindingAdapter("imageUrl")
fun loadImage(view: ImageView, imageUrl: String) {
    Glide.with(view)
        .load(imageUrl)
        .into(view)
}

and I tried to use the adapter like this

   <ImageView
            ...
            app:imageUrl="@{`http://pngimg.com/uploads/alfa_romeo/alfa_romeo_PNG75.png`}"
            ... />

but am getting

****/ data binding error ****msg:Cannot find the setter for attribute 'app:imageUrl' with parameter type java.lang.String on android.widget.ImageView.

The weird thing is, when I convert the BindingAdapter to Java from Kotlin, it works.

public class ImageViewBindingAdapter {

    @BindingAdapter("imageUrl")
    public static void setImageUrl(ImageView view, String url) {
        Glide.with(view)
                .load(url)
                .into(view);
    }
}

NOTE: This issue only exist with the library module. App module works perfectly fine with the Kotlin file.

What am I doing wrong ?

like image 547
theapache64 Avatar asked Feb 07 '19 21:02

theapache64


2 Answers

Duplicated: https://stackoverflow.com/a/52668004/1607169

TL;DR:

apply plugin: 'kotlin-kapt'
like image 134
webzooh Avatar answered Sep 27 '22 19:09

webzooh


@BindingAdapter("imageUrl") 

instead of

@BindingAdapter("app:imageUrl")
like image 20
secret paladin Avatar answered Sep 27 '22 19:09

secret paladin