18.1 Find View by Id and Synthetic Properties
As outlined in the chapter entitled “The Anatomy of an Android Application”, all of the resources that make up an application are compiled into a class named R. Amongst those resources are those that define layouts. Within the R class is a subclass named layout, which contains the layout resources, including the views that make up the user interface. Most apps will need to implement interaction between the code and these views, for example when reading the value entered into the EditText view or changing the content displayed on a TextView.
Over the years, a number of different approaches to referencing layout views have been introduced. The oldest option involves writing code to manually find a view based on its id via a method named findViewById(). For example:
val myTextView: TextView = findViewById(R.id.myTextView)
With the reference obtained, the properties of the view can then be accessed. For example:
myTextView...