Kotlin offers developers many time-saving features that help us create clean code. One of those features is the ability to drop the
findViewById() method and replace it instead simply with the View’s
id value. For example, here is an XML layout that was created in Android Studio. It includes the default
EditText with an id of
The same layout is opened in Text mode below.
To access the TextView we need to use findViewById() and pass in the
In lines 15-16 we get a reference to the
TextView by passing
findViewById it’s id. But with the introduction of Kotlin we not longer need to do this. We can simply call
welcomeMessage.text = "Hi there!".