O'Reilly logo

Android Programming: The Big Nerd Ranch Guide by Brian Hardy, Bill Phillips

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Updating the Controller Layer

In the previous chapter, there was not that much happening in GeoQuiz’s one controller, QuizActivity. It displayed the layout defined in activity_quiz.xml. It set listeners on two buttons and wired them to make toasts.

Now that you have multiple questions to retrieve and display, QuizActivity will have to work harder to tie GeoQuiz’s model and view layers together.

Open QuizActivity.java. Add variables for the TextView and the new Button. Also, create an array of TrueFalse objects and an index for the array.

Listing 2.6  Adding variables and a TrueFalse array (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​;​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required