Wiring Up Widgets

Now that the buttons have resource IDs, you can access them in QuizActivity. The first step is to add two member variables.

Type the following code into QuizActivity.java. (Do not use auto-complete; type it in yourself.) After you save the file, it will report two errors.

Listing 1.8  Adding member variables (QuizActivity.java)

p​u​b​l​i​c​ ​c​l​a​s​s​ ​Q​u​i​z​A​c​t​i​v​i​t​y​ ​e​x​t​e​n​d​s​ ​A​c​t​i​v​i​t​y​ ​{​

 ​ ​ ​ ​p​r​i​v​a​t​e​ ​B​u​t​t​o​n​ ​m​T​r​u​e​B​u​t​t​o​n​;​
 ​ ​ ​ ​p​r​i​v​a​t​e​ ​B​u​t​t​o​n​ ​m​F​a​l​s​e​B​u​t​t​o​n​;​ ​ ​ ​ ​@​O​v​e​r​r​i​d​e​ ​ ​ ​ ​p​u​b​l​i​c​ ​v​o​i​d​ ​o​n​C​r​e​a​t​e​(​B​u​n​d​l​e​ ​s​a​v​e​d​I​n​s​t​a​n​c​e​S​t​a​t​e​)​ ​{​ ​ ​ ​ ​ ​ ​ ​ ​s​u​p​e​r​.​o​n​C​r​e​a​t​e​(​s​a​v​e​d​I​n​s​t​a​n​c​e​S​t​a​t​e​)​;​ ...

Get Android Programming: The Big Nerd Ranch Guide 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.