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() - Android Tutorial
From the course: Android Development Essential Training: 2 User Interface Design
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…
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
-
-
-
-
-