Android-绑定适配器不起作用 [英] Android - Binding adapter not working

查看:226
本文介绍了Android-绑定适配器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have create a binding adapter to display picture with picasso, but it doesn't work. I have the following error :

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

Found data binding errors. ****/ data binding error ****msg:Cannot find the setter for attribute 'app:loadPicture' with parameter type java.lang.String on android.widget.ImageView. file:/home/groupevsc.com/mathieu_labar/Documents/Projects/android-jetpack/app/src/main/res/layout/activity_detail_movie.xml loc:27:31 - 27:52 ****\ data binding error ****

这是我的绑定适配器:

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":

And my XML has attribute "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

Here is my GitHub repository: https://github.com/mlabar/android-jetpack/tree/tech_ajout_databinding

有人会解决我的问题吗?

Would anyone have an idea to solve my problem?

谢谢!

推荐答案

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

Thank you @Blackbelt to solve my problem, i have added "kotlin-kapt" in all my build.gradle modules:

apply plugin: 'kotlin-kapt'

这篇关于Android-绑定适配器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆