这是个比较简单的事情。
假设你的列表item布局中有这么一个ImageView:
<ImageView
android:id="@+id/category_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@{xxxItemViewModel.imageResId}"/>
那么在xxxItemViewModel中相应的get方法应该是这样的:
public Drawable getImageResId() {
return ContextCompat.getDrawable(context,R.drawable.pic);
}
是不是太简单了。
就是这样一个小问题。注意是Drawable类型。