O'Reilly logo

Kotlin Programming: The Big Nerd Ranch Guide, First Edition by David Greenhalgh, Josh Skeen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Wiring Up Views

To display the character data in the UI, you will first retrieve each view element that will display text using a function available on NewCharacterActivity (via inheritance) called findViewById. findViewById accepts a view element id (the android:ids defined in the XML) and returns the view element if a match is found.

In NewCharacterActivity.kt, update onCreate to look up each view element that will display data by its id and assign it to a local variable:

Listing 21.2  Looking up view elements (NewCharacterActivity.kt)

class NewCharacterActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_new_character)
        val ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required