From the course: Android Development Essential Training: The User Interface with Kotlin

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 findViewById()

Get view references with findViewById() - Android Tutorial

From the course: Android Development Essential Training: The User Interface with Kotlin

Start my 1-month free trial

Get view references with findViewById()

- [Instructor] Throughout this course, I'm depending on the use of a tool that's available in Android Studio when you're programming with Kotlin, that let's you automatically get references to view objects in your XML layout files. It's called synthetic binding. And it's enabled by these import statements that Android Studio sometimes adds automatically as you're coding. Whenever you add a reference to a view object in your XML layout file, if the import that's required isn't there, Android Studio just adds it for you. And variables like this linear layout variable somehow magically appear. This variable isn't declared anywhere in my class, but it successfully references this linear layout component that's declared in my layout file. There are, however, times when you'll want to go back to the older, stable, dependable approach to getting view references using the function find view by id. And here's how it works in Kotlin. First, declare variables that you want to use to track your…

Contents