我在项目中很难让 @BindingAdapter
生效。
@BindingAdapter("imageUrl")
public static void setImageUrl(ImageView imageView, String url) {
Log.d("TEST","URL: " + url);
}
以上代码展示了它在我的ViewModel中是如何实现的。没什么特别的。
<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="@drawable/placeholder_image"/>
这不能工作。应用程序命名空间未绑定。那么我错过了什么。我尝试了以下内容https://medium.com/google-developers/android-data-binding-custom-setters-55a25a7aea47#.6ygaiwooh并查看他们如何设置bindingAdapter。但是我错过了某些东西