Home » Android » How can I pass multiple arguments via xml for a custom setter when using Android data binding

How can I pass multiple arguments via xml for a custom setter when using Android data binding

Posted by: admin June 15, 2020 Leave a comment

Questions:

Suppose I have a custom setter method where I need two arguments:

@BindingAdapter({"imageUrl", "placeholder"})
public static void loadImage(ImageView imageView, String imageUrl, Drawable drawable) {
     Picasso.with(imageView.getContext()).load(imageUrl).placeholder(drawable).into(imageView);
}

What would the corresponding xml look like?

How to&Answers:

Looks like it can be done like this:

<ImageView app:imageUrl=“@{data.imageUrl}”
app:placeholder=“@{@drawable/placeholder}”/>

see http://developer.android.com/intl/es/tools/data-binding/guide.html