android - 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
有人有想法解决我的问题吗?
谢谢!
解决方案
谢谢@Blackbelt 解决了我的问题,我在所有build.gradle
模块中都添加了“kotlin-kapt”:
apply plugin: 'kotlin-kapt'
推荐阅读
- css - Full width non responsive CSS for mobile only and only on Woocommerce single pages
- django - Django - 通过 Google API 转换经纬度地址并保存对象
- python - 检查多个正则表达式模式
- knapsack-problem - 如何重新包装多个最大容量的背包,将他们的物品倾倒在一堆,洗牌,并移除一些物品?
- c# - c# tabControl 背景颜色
- javascript - 按下单选标签双触发 onclick 事件。解决这个问题的最佳方法?
- html - 为什么过渡时间对颜色起作用,而不是文本对齐?
- php - 如何获取从 gmail API 发送的电子邮件
- javascript - 在服务器上运行 Angular 应用程序时,从 musickit.js 修复“无法准备好属性 'container' of null”
- webpack - Gulp 到 Webpack 4 仅在旧项目中连接和缩小