A tour through the data binding framework's obvious and not-so-obvious perks. Reduce boilerplate, avoid NullPointerExceptions, decrease code complexity, and maybe even fix some Android pet peeves.
Problem: Repetitive Java boilerplate @{dataBinding} findViewById, casts setters are verbose/confusing XML layout is limited Manually keep track of UI updates
binding.setPet(pet); PetDetailBinding binding = DataBindingUtil.setContentView (this, R.layout.pet_detail); Your old layout goes here Your model object
enum VOTE { UPVOTE, DOWNVOTE, NONE } public class VoteState { public final ObservableField vote = new ObservableField(); } voteState.vote.set(VOTE.DOWNVOTE) Persistent binding
Android Studio tips xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> tools:text=“Jane Doe” tools:ignore="UnusedAttribute" Declare namespaces in layout tag Use tools: prefix for layout preview Ignore lint warnings