Skip to content

Instantly share code, notes, and snippets.

@ivacf
Created September 25, 2015 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivacf/1b49148550cd7ffc375e to your computer and use it in GitHub Desktop.
Save ivacf/1b49148550cd7ffc375e to your computer and use it in GitHub Desktop.
View model that exposes a method using @BindingAdapter to load an image given a url
public class ProfileViewModel {
public String getImageUrl() {
// The URL will usually come from a model (i.e Profile)
return "http://cdn.meme.am/instances/60677654.jpg";
}
@BindingAdapter({"bind:imageUrl"})
public static void loadImage(ImageView view, String imageUrl) {
Picasso.with(view.getContext())
.load(imageUrl)
.placeholder(R.drawable.placeholder)
.into(view);
}
}
@lockingroad
Copy link

app:imageUrl="@{viewModel.imageUrl}"
@BindingAdapter({"bind:imageUrl"})

1 should be the same with 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment