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 - Android Tutorial
From the course: Android Development: Data Binding
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Overview of observables1m 51s
-
(Locked)
Binding to observables4m 49s
-
(Locked)
Binding to ViewModels6m 25s
-
(Locked)
Using binding adapters7m 19s
-
(Locked)
Two-way binding syntax4m 45s
-
(Locked)
Using converters4m 2s
-
(Locked)
Challenge: Color binding adapter1m 18s
-
(Locked)
Solution: Color binding adapter2m 26s
-
(Locked)
-