Skip to content

Instantly share code, notes, and snippets.

@diegoy
Last active August 31, 2016 19:33
Show Gist options
  • Save diegoy/6d1cbd0c78427d3c02b8a1c791a3f155 to your computer and use it in GitHub Desktop.
Save diegoy/6d1cbd0c78427d3c02b8a1c791a3f155 to your computer and use it in GitHub Desktop.
/**
* This binder is needed to prevent a NullPointerException cases when
* Android's Data Binding Library Binder class tries to bind the value
* for rating when the model isn't setted yet.
* */
public class RatingBinder {
@BindingAdapter({"rating"})
public static void setRating(RatingBar ratingBar, Float rating) {
if (rating != null) {
ratingBar.setRating(rating);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment