Missing ID ◦ Wrong cast ◦ Multiple layout configurations can have different elements • Each findViewById requires a layout traversal • Only the main thread can access those elements • It’s boilerplate code ◦ A few libraries to the rescue (eg Butterknife)
and mediate the communication between model and views. • Separation of presentation logic and business logic • Testability Source: https://goo.gl/d0oxj7 MVVM MVVM picture
placeholder elements specified through the data binding notation, but the UI elements don't change the values in the model. Changes in the model are not propagated to the view. Source: https://goo.gl/fo3797 Databinding models One-Way Data Binding
placeholder elements specified through the data binding notation. Any changes to the view are immediately reflected in the model, and any changes in the model are propagated to the view. Source: https://goo.gl/fo3797 Databinding models Two-Way Data Binding
provides a mechanism to implement an hybrid approch between one-way and two-way databinding in wich model changes are reflected to the UI. To implement that we have two options: • Using Observable Objects • Using Observable Fields
the @Bindable annotation provided by the Data Binding Library and notify the changes in the setter. • For each method annotated the compiler will generate a corrisponding field in the BR class. If case we don’t want or we can’t extend from BaseObservable we can implement the Observable interface.
ObservableShort, ObservableInt, ObservableLong, ObservableFloat, ObservableDouble, and ObservableParcelable. public class Ad { public final ObservableField<String> subject = new ObservableField<>(); } //Setting the value will refresh the components observing this field mAd.subject.set("iPhone for sale");
Notify whether items are added, changed, moved or removed • ObservableMap ◦ ObservableArrayMap is the implementation ◦ Notify whether a key is added, removed or changed.
in a more robust and testable way • Keep away your business logic from you views → MVVM • Tools are currently under development so expect big enhacements in the future
Apps Faster with Android Data Binding: https://goo.gl/zkyNwA • Data Binding Techniques @ Droidcon NYC, 2015: https://goo.gl/WsmIYc • Android Databinding: goodbye Presenter, hello ViewModel: http://goo. gl/xnqDWt • MVVM on Android using the Data Binding Library: http://goo.gl/qCXFRc