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 ...

Get Kotlin Programming: The Big Nerd Ranch Guide, First Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.