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

Work with synthetic view bindings - Android Tutorial

From the course: Android Development Essential Training: App Architecture with Kotlin

Start my 1-month free trial

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