May 2022
Intermediate to advanced
688 pages
20h 12m
English
You are ready to wire up your button views. This is a two-step process:
get references to the inflated View objects
set listeners on those objects to respond to user actions
Now that the buttons have resource IDs, you can access them in MainActivity. Type the following code into MainActivity.kt (Listing 1.4). (Do not use code completion; type it in yourself.) After you enter each line, it will report an error.
Listing 1.4 Accessing view objects by ID (MainActivity.kt)
class MainActivity : AppCompatActivity() {
private lateinit var trueButton: Button
private lateinit var falseButton: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ...Read now
Unlock full access