Creating a New Class

In the project tool window, right-click the com.bignerdranch.android.geoquiz package and select NewKotlin File/Class. Enter Question for the name. Select Class from the Kind dropdown. Click OK (Figure 2.2).

Figure 2.2  Creating the Question class

Creating the Question class

Android Studio will create and open a file called Question.kt. In this file, add two member variables and a constructor.

Listing 2.1  Adding to Question class (Question.kt)

class Question {
}
data class Question(@StringRes val textResId: Int, val answer: Boolean)

The Question class holds two pieces of data: the question text and the question answer ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.