From the course: Android Development Essential Training: 2 User Interface Design

Unlock the full course today

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

Get view references with view binding

Get view references with view binding - Android Tutorial

From the course: Android Development Essential Training: 2 User Interface Design

Start my 1-month free trial

Get view references with view binding

- [Instructor] The latest approach for accessing your views in code is view binding. View binding is a feature that allows you to simplify the code that interacts with views, similar to what you get with Kotlin synthetics. How does it work? Once view binding is enabled, for each XML layout file present in your module, a binding class is generated. This binding class contains references to all views that have an ID in the corresponding XML layout. This is what allows us to access the view simply in our code. Let's move over to Android Studio and update our project to use view binding. First, we'll have to let our build know that we want to use view binding by adding it to our list of features. We'll do this inside of our app's build.gradle file in the Android block. So let's come here to line number 17, we'll add a few extra empty lines and we'll create a buildFeatures block. And inside of that block, we'll…

Contents