Let's explore how we can use the data binding library to reduce the boilerplate code for the Android views. We'll examine how you can start creating declarative layouts to bind the application logic to your views.
22. What we did?
11
• Wrap Parent ViewGroup in <layout> tag
• Move all namespaces to <layout> tag
• Define meta data of binding in <data> tag
• Inflate layout using DataBindingUtil
• set the variables defined in <data> tag in binding
24. What we did?
11
• Created a viewModel to hold view state
• Extend viewModel with BaseObservable
• Create setters for the fields
• Notify when data changes in viewModel
• @={viewModel.title}
27. Take Aways…
11
• Use one way binding to update data on UI
• Two way binding to update view model from UI
• Don’t extend viewModel with BaseObservable
for static data
• Use custom binding to avoid duplication and make code
readable in layout
• Do not write too much logic in layout files