【发布时间】:2019-04-19 12:02:49
【问题描述】:
我正在尝试使用自定义 BindingAdapters 让数据绑定在 Android Studio 中工作。
为了设置图像,我定义了以下 BindingAdapter:
@BindingAdapter("app:iconImage")
@JvmStatic fun setIconImage(view: ImageView, cool: Boolean){
view.setImageDrawable(determineImage(cool, view.context))
}
但是,这在构建项目时会引发以下错误:
****/ data binding error ****msg:Cannot find the setter for attribute
'app:iconImage' with parameter type androidx.databinding.ObservableBoolean
on android.widget.ImageView.
这是我的图像视图的 xml:
<ImageView
android:layout_height="100dp"
android:layout_width="100dp"
tools:srcCompat="@drawable/favorite"
app:iconImage="@{myModel.cool}"
app:imageRotation="@{myModel.stars}"
android:id="@+id/imageView" app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/ratingBar"/>
我已经尝试将 'cool' 参数的参数类型更改为 ObservableBoolean 但无济于事。
【问题讨论】:
-
setIconImage是顶级函数吗?还是放在某个类中?
标签: android kotlin data-binding