首页 > 解决方案 > Android - 绑定适配器不起作用

问题描述

我创建了一个绑定适配器来用毕加索显示图片,但它不起作用。我有以下错误:

发现数据绑定错误。****/ 数据绑定错误 ****msg:在 android.widget.ImageView 上找不到参数类型为 java.lang.String 的属性“app:loadPicture”的设置器。文件:/home/groupevsc.com/mathieu_labar/Documents/Projects/android-jetpack/app/src/main/res/layout/activity_detail_movie.xml 位置:27:31 - 27:52 ****\ 数据绑定错误 * ***

这是我的绑定适配器:

object CommonBindingUtil {

    @JvmStatic
    @BindingAdapter("loadPicture")
    fun loadPicture(view: ImageView, text: String) {
        Picasso.with(view.context)
                .load(text)
                .error(R.drawable.ic_movie_24)
                .fit()
                .placeholder(R.drawable.ic_movie_24)
                .into(view)
    }

}

我的 XML 有属性 "app:loadPicture" :

<ImageView
    android:id="@+id/picture"
    android:layout_width="@dimen/material_image_simple_width"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:src="@drawable/ic_movie_24"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:loadPicture="@{viewModel.movie.Poster}"/>

这是我的 GitHub 存储库: https ://github.com/mlabar/android-jetpack/tree/tech_ajout_databinding

有人有想法解决我的问题吗?

谢谢!

标签: androidkotlinpicassoandroid-binding-adapter

解决方案


谢谢@Blackbelt 解决了我的问题,我在所有build.gradle模块中都添加了“kotlin-kapt”:

apply plugin: 'kotlin-kapt'

推荐阅读