android - Imageview 的图像未在数据绑定中的 bindingadapter 中设置
问题描述
我正在尝试通过绑定适配器在图像视图中设置图像。我正在传递两个参数、一个图标和一个条件。我已登录以检查该函数是否被调用。该函数被调用,但图像视图未设置图像。
图像视图代码:
<ImageView
android:id="@+id/iv_remove"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="16dp"
isEntryField="@{group_field_wtih_values.is_entry_field}"
icon="@{group_field_wtih_values.is_entry_field ? ResourceProvider.enabledRemoveBtn:ResourceProvider.disabledRemoveBtn}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
绑定适配器代码:
@BindingAdapter({"icon","isEntryField"})
public static void setImageResource(ImageView imageView,Integer icon,boolean isEntryField){
Log.e("setImageResources",String.valueOf(icon));
if (!isEntryField)
imageView.setImageDrawable(imageView.getContext().getResources().getDrawable(icon));
}
解决方案
推荐阅读
- python - 如何创建具有不同行长的多列的新 python DataFrame?
- git - Git:显示所有文件的状态,甚至未更改/忽略
- javascript - 从另一个选项卡或窗口获取 json
- python - 无法在 google colab 中读取自行准备的 csv 文件
- ios - AwakeFromNib 没有出口
- visual-studio - 在 azure 上发布时在 Visual Studio 中发布卡住
- xamarin - Appcenter / HockeyApp 的替代方案,用于托管移动应用程序
- django - 在 Django Admin 中创建两步对象
- firebase - 使用 FCM 更新 Firestore DB 时在 Flutter 应用程序上收到通知
- azure - 在 Azure 中检查 Databricks 运行时的版本