Replacing findViewById with Kotlin synthetic imports

Old way:

findViewById() (the old way).

New way:

Kotlin synthetic import.

This is possible because of Kotlin synthetic imports. Just type the TextView's id, that's it.

The TextView.

Just make sure the TextView has an ID that matches the Kotlin code. For clarity, here is the Kotlin import:

The imports that make this possible.

This is another way Kotlin allows developers to do more when less code. I've used Kotlin for two years and never regret having to type less.

By Daniel Malone

Daniel Malone is an Android Developer in Austin, Texas. He enjoys writing code, whether it be HTML, CSS, JavaScript, PHP, Java, XML or Kotlin. Daniel started writing code at age 12. By the time he was 15, he had a technology news website that received about 200 visitors a day. His first computer was a Dell Dimension 3000, with an 80GB hard drive, 512MB RAM and a broken DVD drive.