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

Unlock the full course today

Join today to access over 22,500 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: 2 User Interface Design

Start my 1-month free trial

Get view references with findViewById()

- [Instructor] One of the classic ways to access your views is by means of the 'find view by I.d.' Method. You may have seen examples of Kotlin based Android Studio projects that use synthetics to access views. Those synthetic properties were generated from the id values of views in our layout file. Let's navigate to our activity main layout file. From here, you have a few views with ID's defined like the floating action button here on line 26, and, if we scroll up a bit, we also see an ID for the toolbar here on line 15. We can use those ID's directly in our code to reference the views when working with Kotlin synthetics. However, it can have unpredictable behavior in more complex layouts and application structures. At the time of this recording, sample ad's generated by Android Studio use the 'find views by ID' method. Let's go back to our main activity class. Here, we see two examples of it's usage in the…

Contents