Android How to Program Chapter 04 Solution Manual
Download file with the answers
Android How to Program Chapter 04 Solution Manual
1 file(s) 282.42 KB
If you are not a member register here to download this file
4 Tip Calculator App
Obj e c t i v e s
In this chapter you’ll:
■ Design a GUI using a
TableLayout.
■ Use the ADT Plugin’s
Outline window in Eclipse to
add GUI components to a
TableLayout.
■ Directly edit the XML of a
GUI layout to customize
properties that are not
available through the Visual
Layout Editor and
Properties window in
Eclipse.
■ Use TextView, EditText
and SeekBar GUI
components.
■ Use Java object-oriented
programming capabilities,
including classes,
anonymous inner classes,
objects, interfaces and
inheritance to create an
Android app.
■ Programmatically interact
with GUI components to
change the text that they
display.
■ Use event handling to
respond to user interactions
with an EditText and a
SeekBar.
Self-Review Exercises 2
Self-Review Exercises
4.1 Fill in the blanks in each of the following statements:
a) An —often called a text box or text field in other GUI technologies—is a
subclass of TextView that can display text and accept text input from the user.
b) Use a to arrange GUI components into rows and columns.
c) When working with more complex layouts like TableLayouts, it’s difficult to see the
nested structure of the layout and to place components in the correct nested locations
using the Visual Layout Editor. The window makes these tasks easier because
it shows the nested structure of the GUI. So, in a TableLayout, you can select the
appropriate row and add a GUI component to it.
d) Class of package android.os represents an app’s state information.
e) You implement interface of package android.text to respond to events
when the user interacts with an EditText component.
f) A separate is typically associated with each screen of an app.
g) The method is called by the system when an Activity is starting—that is,
when its GUI is about to be displayed so that the user can interact with the Activity.
h) As you build your app’s GUI and add resources (such as strings in the strings.xml file
or GUI components in the main.xml file) to your app, the ADT Plugin tools generate
a class named that contains nested static classes representing each type of
resource in your project’s res folder.
i) Class (nested in class R)—contains constants for any drawable items, such
as images, that you put in the various drawable folders in your app’s res folder.
j) Class (nested in class R)—contains constants for each String in the
strings.xml file.
k) Once the layout is inflated, you can get references to the individual widgets using Activity’s
method. This method takes an int constant for a specific view
(that is, a GUI component) and returns a reference to it.
l) You use a TableLayout to arrange the GUI components into and
4.2 State whether each of the following is true or false. If false, explain why.
a) Android requires that you use the GUI component’s class name in each component’s
Id property in the XML layout and in each component’s variable name in the Java code.
b) You can force an EditText to display a cursor so that the user can’t manipulate the text.
3 Chapter 4 Tip Calculator App
c) Each component’s Relative weight determines how it should be sized relative to other
components.
d) As with all Java programs, Android apps have a main method.
e) An active (or running) activity is visible on the screen and “has the focus”—that is, it’s
in the background. This is the activity the user is interacting with.
f) A stopped activity is visible on the screen and is likely to be killed by the system when
its memory is needed.
g) Method onCreate typically initializes the Activity’s instance variables and GUI components.
This method should be as simple as possible so that the app loads quickly. In
fact, if the app takes longer than five seconds to load, the operating system will display
an ANR (Application Not Responding) dialog—giving the user the option to forcibly
terminate the app.
Exercises
4.3 Fill in the blanks in each of the following statements:
a) String literals should be placed in the strings.xml file in the app’s folder—
especially if you intend to localize your app for use with multiple languages.
b) You can control whether or not the user can give the focus to an EditText by setting its
property.
c) A component’s specifies its relative importance with respect to other components.
d) Class of package android.app provides the basic lifecycle methods of an
app.
e) Interface of package android.text allows you to change the content and
markup of text in a GUI.
f) You implement interface of package android.widget to respond to the
user moving the SeekBar’s thumb.
g) Android apps have four types of components—activities, services, content providers
and .
h) Throughout its life an activity can be in one of several states—active (or running),
paused or . The activity transitions between these states in response to various
events.
Exercises 4
i) The method is called by the system when the configuration of the device
changes during the app’s execution—for example, when the user rotates the device or
slides out a keyboard on a device with a hard keyboard.
j) Class (nested in class R)—contains constants for the GUI components in
your XML layout files.
k) Method setContentView uses a received constant to load the corresponding XML document,
which is then parsed and converted into the app’s GUI. This process is known
as the GUI.
4.4 State whether each of the following is true or false. If false, explain why.
a) By default, a Seekbar allows you to select values from 0 to 255.
b) A GUI component can span multiple columns in a TableLayout.
c) If you’ve installed multiple Android SDKs, the ADT Plugin selects the oldest one as the
default for design purposes in the Graphical Layout tab—regardless of the SDK you
selected when you created the project.
d) Every Activity subclass must override the Construct method.
ANS: False. Every Activity subclass must override the onCreate method.
e) A paused activity is visible on the screen and has the focus.
f) Time-consuming initializations should be done in a onCreate method instead of the
background process.
g) You use TableRows to create the rows in a TableLayout.
h) You override the onStart method to initialize the app when it’s launched.
Leave a reply