6 Flag Quiz Game App Objectives In this chapter you’ll: ■ Store String arrays in strings.xml. ■ Store a set of images in subfolders of the assets folder. ■ Use an AssetManager to get a list of all assets in an app. ■ Use random-number generation to vary flag choices. ■ Use a Drawable to display a flag image in an ImageView. ■ Use a tweened animation to shake the displayed flag when the user specifies an incorrect answer. ■ Use a Handler to schedule a future action. ■ Use an ArrayList to hold collections of items and a HashMap to hold name–value pairs. ■ Override Activity’s onCreateOptionsMenu method to create a Menu and MenuItems that enable the user to configure the app’s options. ■ Use Android’s logging mechanism to log error messages. 2 Chapter 6 Flag Quiz Game App Self-Review Exercises 6.1 Fill in the blanks in each of the following statements: (package android.cona) Files in the assets folders are accessed via an tent.res), which can provide a list of all of the file names in a specified subfolder of assets and can be used to access each asset. ANS: AssetManager. animation moves a View within its parent. b) A ANS: translate. c) By default, animations in an animation set are applied in parallel, but you can use the attribute to specify the number of milliseconds into the future at which an animation should begin. This can be used to sequence the animations in a set. ANS: android:startOffset. d) To access the app’s assets folder’s contents, a method should get the app’s AssetManager by calling method (inherited indirectly from class ContextWrapper). ANS: getAssets. is a set of styles that specify the appearance of a GUI’s components. e) A ANS: theme. 6.2 State whether each of the following is true or false. If false, explain why. a) We use AnimationUtils static method loadAnimation to load an animation from an XML file that specifies the animation’s options. ANS: True. b) Android does not provide a logging mechanism for debugging purposes. ANS: False. When exceptions occur, you can log them for debugging purposes with Android’s built-in logging mechanism, which uses a circular buffer to store the messages for a short time. c) ImageView attribute android:adjustViewBounds specifies whether or not the ImageView maintains the aspect ratio of its Drawable. ANS: True. d) You load color and String array resources from the colors.xml and strings.xml files into memory by using the Activity’s Resources object. ANS: True. Exercises 6.3 Fill in the blanks in each of the following statements: is called to a) When the user selects an item from a Menu, Activity method respond to the selection. ANS: onOptionsItemSelected. (package android.os) object to execute a Runb) To delay an action, we use a nable after a specified delay. ANS: Handler. c) We also specify the number of times an animation should repeat with Animation methand perform the animation by calling View method startAnimation od (with the Animation as an argument) on the ImageView. ANS: setRepeatCount. is a collection of animations which make up a larger animation. d) An ANS: animation set. animations which allow you to animate any property of e) Android supports any object. ANS: property. 3 f) For the android:fromXDelta attribute, specifying the value -5%p indicates that the View should move to the by 5% of the parent’s width (indicated by the p). ANS: left. attribute of the application element to apply a theme to the g) We use the application’s GUI. ANS: android:theme. 6.4 State whether each of the following is true or false. If false, explain why. h) You can use the android:screenOrientation attribute to specify that an app should always appear in landscape mode (that is, a vertical orientation). ANS: False. You can use the android:screenOrientation attribute to specify that an app should always appear in portrait mode (that is, a vertical orientation). i) You specify the number of times an animation should repeat with Animation method repeatCount. ANS: False. You specify the number of times an animation should repeat with Animation method setRepeatCount.
© Copyright 2026 Paperzz