Data Binding

Custom Setters

I would like to custom the setter for the android:src attribute. A static binding adapter method with the BindingAdapter annotation allows me to customize how a setter for an attribute is called.

public class MyViewModel {

  @BindingAdapter("android:src")
  public static void loadImage(ImageView view, Drawable drawable) {
    GlideApp.with(view.getContext())
        .load(null)
        .placeholder(drawable)
        .into(view);
  }

}

Set drawable resource ID in android:src for ImageView using data binding in Android of Stack Overflow

Set image resource to TextView

TextView only receives the Drawable object, so we have to binding the resource Id to attribute of TextView.

Load drawableLeft image for Button using databinding

results matching ""

    No results matching ""