Updating the Layout

Now that you have defined the Question class, you are going to update GeoQuiz’s UI to include a NEXT button.

In Android, UI is typically inflated from XML within a layout file. The sole layout in GeoQuiz is defined in activity_main.xml. This layout needs to be updated as shown in Figure 2.4. (Note that to save space we are not showing the attributes of unchanged views.)

Figure 2.4  New button!

New button!

So the changes you need to make to the layout are:

  • Give the TextView an android:id attribute. This view will need a resource ID so that you can set its text in MainActivity’s code.

  • Position the TextView’s ...

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.