android - 绑定(bind)适配器无法正常工作

标签 android data-binding android-databinding android-binding-adapter

我很难让 @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"/>

这是行不通的。命名空间应用未绑定(bind)。那我错过了什么。我试过以下 https://medium.com/google-developers/android-data-binding-custom-setters-55a25a7aea47#.6ygaiwooh 并查看他们如何设置 bindingAdapter。但是我错过了一些东西

最佳答案

我遇到了同样的问题,我错过了绑定(bind)布局使用:

DataBindingUtil.setContentView(activity, layoutResId);

关于android - 绑定(bind)适配器无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41533341/

相关文章:

date - 如何获取日期的日期选择器?

android - 将 Activity 实例化为新的任务和流程

mysql - 从电力读数mysql计算使用的千瓦时

android - 从相机捕获后如何旋转图像

android - android studio 中的数据绑定(bind)基础。 ActivitymainBinding 不是 ViewDataBinding 的子类型

java - Android 数据绑定(bind)测试在模块 NoClassDefFoundError 中失败

android - Realm 和 Android 数据绑定(bind)

android - lateinit 属性性别尚未初始化

android - 允许其他应用程序从我的应用程序中选择图像,例如图库

android - 如何将 ARC Welder 用作 Android 模拟器