android-binding-adapter

Binding Adapter not working properly

a 夏天 提交于 2019-12-08 15:42:18
问题 I have a hard time making @BindingAdapter to work in my project. @BindingAdapter("imageUrl") public static void setImageUrl(ImageView imageView, String url) { Log.d("TEST","URL: " + url); } Above code shows how it is implemented in my ViewModel. Nothing special. <ImageView android:id="@+id/image_holder" android:layout_width="match_parent" android:layout_height="wrap_content" android:scaleType="centerCrop" android:layout_below="@id/profile_container" app:imageUrl="@{item.imageUrl}" tools:src="

Why is this BindingAdapter not working in Kotlin?

北战南征 提交于 2019-12-04 08:22:04
I have a ViewModel with: val imageUrl = ObservableField<String>() My layout XML has: <ImageView ... app:url="@{viewModel.imageUrl}" .../> I have a BindingAdapters file with a top level function: @BindingAdapter("url") fun loadImage(view: ImageView, url: String?) { ... } I'm getting the following error: data binding error msg:Cannot find the setter for attribute 'app:url' with parameter type android.databinding.ObservableField<java.lang.String> on android.widget.ImageView. Any idea why this would be? This is pretty much identical to how I set up binding adapters in Java, minus the static