From the course: Android Development: Data Binding
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Binding to ViewModels - Android Tutorial
From the course: Android Development: Data Binding
Binding to ViewModels
- [Instructor] We've seen how binding to observable data sources can solve the problem of getting changes to the data to propagate to the layout. But in the previous example, we used observable fields within our data class. In this example, we're going to use the ViewModel, one of the Android architecture components as the data model instead of a custom class that uses observable fields. This has some advantages over the observable class model. Most importantly that ViewModels understand the activity lifecycle. If you're not already familiar with ViewModels, then you might want to review the architecture components documentation and specifically the docs for the ViewModel class at this link. All right, so let's go to Android Studio and let's build the code for this example. So first, let's open the code for the activity and that is going to be here in the ViewModExample. This code is not really that much different…
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.