From the course: Android Development Essential Training: App Architecture with Kotlin
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Work with synthetic view bindings - Android Tutorial
From the course: Android Development Essential Training: App Architecture with Kotlin
Work with synthetic view bindings
- [Instructor] When you program Android apps with Kotlin, you get a lot of special features beyond the language itself. One of these is a tool called synthetic view binding. When you create a brand-new Android app in Android Studio it'll typically have this import at the top, referencing an activity layout file. Activity_main.xml is the primary layout file. And it has a couple of components that have IDs assigned. So there's a toolbar component that has and ID of toolbar and a floating action button that has an ID of fab. In the MainActivity class there are references to these components, here for the toolbar and here for the floating action button. There isn't any apparent code that's creating those variables. Instead, this import statement is creating a bunch of generated code in the background. It's interrogating the layout files, finding view components that have IDs and then creating the variables that you need. Now you can do the same thing for other components in other layout…
Contents
-
-
-
-
Work with synthetic view bindings5m 10s
-
Get view references with findViewById()4m 53s
-
Handle view events with lambdas5m 26s
-
Create companion object functions6m 16s
-
Update display from new data4m 47s
-
Restore state after orientation change7m 10s
-
Add a ViewModel to an activity4m 43s
-
Subscribe to changes in LiveData values7m 57s
-
-
-
-