Introduction
Data binding, published in the 2015 Google I/O Conference, aims to reduce the number of template code (such as Findviewbyid ()) in Android development, add code and logical clarity, and improve development efficiency and maintenance efficiency.
What is Data Binding
Data binding, or databinding, is a way for the Android team to implement the MVVM architecture so that data (objects) can be directly bound to the layout's XML, and data changes are reflected directly on the view.
At the same time, the Data binding also supports two-way binding.
What good is it?
- Save a lot of template code, such as Findviewbyid (), Setonclicklistener (), SetText (), and so on.
- Makes view and logic complete decoupling (MVVM) possible, unlike MVC, where logic is difficult to maintain with view operations, and does not define a large number of interfaces like MVP, which can be time consuming and laborious.
- Since the data (object) is bound to the view in two directions, it is only necessary to focus on the data (object) in development, without concern for the various miscellaneous operations of the view (e.g. Setvisibility (), SetText (), etc.)
- Powerful, simple logic in XML (supports expression language, logical/mathematical operations, etc.)
Easy to use?
The integration is simple and easy to use, enabling your project to support data Binding with just one configuration.
android { … dataBinding { enabled = true }}
Specific use steps, you can click Next: Data Binding integration and configuration
Android development Tutorial-Using Data Binding (a) Introduction