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 - Android Tutorial
From the course: Android Development Essential Training: 2 User Interface Design
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…
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
-
-
-
Position views with LinearLayout4m 44s
-
Manage positions with constraints4m 52s
-
Distribute views with constraint chains4m 37s
-
Display views programmatically5m 20s
-
Get view references with findViewById()2m 34s
-
Get view references with view binding5m 35s
-
Challenge: Get in line50s
-
Solution: Get in line3m 33s
-
-
-
-
-