From the course: Android Development: Data Binding

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Two-way binding syntax

Two-way binding syntax - Android Tutorial

From the course: Android Development: Data Binding

Start my 1-month free trial

Two-way binding syntax

- [Instructor] Up until this point, we've only looked at data binding as a one-way operation. But data binding actually does work in both directions. You can set the value of an attribute but you can also have that attribute push new values back into the data model. So let's open the TwoWayExample activity. And you can see that this code uses the WeatherViewModel that we've defined previously. And this code actually doesn't need to change at all. So let's take a look at the WeatherViewModel. And remember that I made this current_temperature property a MutableLiveData and that means not only can the value be read, it can be written by whatever endpoint binds to it and this is why I made it mutable instead of just a regular LiveData so that we could do this example. All right, so now let's go to the two-way binding layout file and that's this code right here. And I'll scroll up and let's get some more room. It's pretty…

Contents