We're checking out new data binding lib announced on the last Google I/O. We'll go in depth of data binding - goals, benefits and drawbacks. Less code should mean less bugs - in theory.
2. WHAT IS DATA BINDING?
• Process that establishes a connection between the
application UI and Business logic.
• UI reflects data changes when made
• Announced on the Google I/O 2015
3. REQUIREMENTS
• API level 7+ (Android 2.1 Eclair)
• Android Studio with Android Gradle plugin 1.3.0-beta4 or
higher
• Data binding lib (currently RC)
7. BIND IT
• Several ways of binding:
• DataBindingUtil.setContentView({activity}, {layout});
• DataBindingUtil.bind({view});
• DataBindingUtil.inflate({inflater}, {layout}, {parentView},
{attachToParent});
8. WHAT DO WE GET?
• Data binding lib will generate object with name of your
layout in camel case, suffixed with Binding
• list_item_film.xml → ListItemFilmBinding
• on that object we can set variables which are defined in our
layout
18. NO IT IS NOT
• ObservableCollections
• Event Bindings (OnClick, OnLongClick, etc)
• Dynamic Bindings (for the adapters)
• Custom Setters (for properties which do not have same
name as methods in Java - e.g. padding)
21. SHOULD WE USE IT?
• You can, on your own risk. - Why?, you ask.
• RC release
• Might contain bugs
• Subject to significant changes which might not be
compatible with your app
• without APT - AS can’t find generated classes
22. HOW SHOULD WE USE IT?
• Databinding allows some kind of logic in layouts
• Databinding allows various imports in the layouts
• Be smart - don’t do it or you’ll have bonding time with AS
debugger when output is not what you desire
23. WHAT TO READ?
• http://developer.android.com/tools/data-binding/
guide.html#custom_binding_class_names
• https://realm.io/news/data-binding-android-boyar-mount/
• https://www.reddit.com/r/androiddev/comments/3f9c3v/
android_data_binding_moves_some_logic_to_xml_is/
• https://code.google.com/p/android/issues/list?can=2&q=Data
+binding&colspec=ID+Type+Status+Owner+Summary
+Stars&cells=tiles