MV[C|P|VM] A Model that represents your raw data. Aka POJOs. A View that dictates how your data is displayed to the user Something to get the data and display the view
Let there be data binding Now we can have better separation of concerns Activities and Fragments now have more limited scope and a clearer purpose: ◦ Load data ◦ Bind data to the View ◦ Respond to events
The View- step three android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@{animal.species}"/> Bind to model with @{model.property}
Data binding: Two way street android:orientation="vertical“ android:layout_width="match_parent" android:layout_height="match_parent" app:onClickListener="@{note.clickListener}"> Using app namespace, bind to anything with a setter
Observables in the ViewModel public ObservableInt numClicks; public View.OnClickListener clickListener = new View.OnClickListener() { @Override public void onClick(View view) { numClicks.set(numClicks.get() + 1); } };
Observables in the layout android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@{String.valueOf(note.numClicks)}"/> Text now automatically updates
Resources https://developer.android.com/tools/data-binding/guide.html Tons of information about: ◦ s ◦ Operators in bindings ◦ Accessing arrays/lists/maps ◦ Using resources in bindings ◦ Value converters ◦ Binding custom view properties ◦ More ways to make data observable