5

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 ?

theapache64
  • 10,926
  • 9
  • 65
  • 108

3 Answers3

10

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

TL;DR:

apply plugin: 'kotlin-kapt'
webzooh
  • 356
  • 2
  • 9
2
@BindingAdapter("imageUrl") 

instead of

@BindingAdapter("app:imageUrl")
secret paladin
  • 222
  • 1
  • 8
0

your code should be like this

object BindUtil {
  @JvmStatic
  @BindingAdapter("app:imageUrl")
  fun imageUrl(view: ImageView, imageUrl: String?) {
      Glide.with(view)
       .load(imageUrl)
       .into(view)
  }
}
Mahdi Zareei
  • 1,299
  • 11
  • 18