Wiring Up the User Interface
First, create a list of Question objects in MainActivity, along with an index for the list.
Listing 2.5 Adding a Question
list (MainActivity.kt
)
class MainActivity : AppCompatActivity() { private lateinit var trueButton: Button private lateinit var falseButton: Button private val questionBank = listOf( Question(R.string.question_australia, true), Question(R.string.question_oceans, true), Question(R.string.question_mideast, false), Question(R.string.question_africa, false), Question(R.string.question_americas, true), Question(R.string.question_asia, true)) private var currentIndex = 0 ... }
Here you call the Question constructor several times and create a list of Question objects.
(In a more complex ...
Get Android Programming: The Big Nerd Ranch Guide, 5th 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.