In this recipe, we are going to explore the view-binding feature provided by the Kotlin Android Extensions plugin. It allows us to obtain references to View type elements declared in the XML layout files in an easy and robust way, without using the original findViewById() function. We are going to declare a TextView element in the Activity layout and obtain a reference to it in order to display a sample text in it.
Clean and safe view-binding with the Android Extensions plugin
Getting ready
In order to make use of the Kotlin Android Extensions plugin, we need to enable it in the Android project module-level build.gradle script by adding the following declaration:
apply plugin: 'kotlin-android-extensions'
You can...