216 CHAPTER 7: Making Apps Interactive: Intents, Event Handling, and Menus
Now you are ready to edit your Menu object, which is defined inside of your main.xml XML menu
definition file, which is located in the /res/menu project folder. Right-click on this /res/menu/main.xml
file, and select the Open option to open this file in your Eclipse central editing pane.
Add a second MenuItem object by adding another
You can further define and configure MenuItem objects using parameters within each
tag, such as the android:id parameter to define the ID that will be evaluated (later) in your Java code,
the android:title parameter, which will reference the edit_galaxy
created for your MenuItem label, and other parameters defining MenuItem order and whether or not
it shows up in the Android ActionBar.
As you can see in Figure 7-2, I placed the edit_galaxy MenuItem object above the action_settings
MenuItem object, as Android menu design convention dictates that Help and Settings menu items
should be last on the menu structure. This is similar to all software menu design guidelines, where
help and settings menus are listed last, at the bottom of the menu.
Figure 7-2. Add an
To see your new Menu object design, use the Run As ➤ Android Application menu sequence and
launch the Nexus One AVD, and click on the hardware MENU button, or on the ActionBar overflow
menu (three vertical dots) to see that your menu now has two entries in it!
It is interesting to note that you can design and test Menu objects and MenuItem objects using
this XML–based work process all day long and the Menu and MenuItem objects will show up in the
AVD, which is a designer’s dream! It will take some Java coding to make these Menu and MenuItem
objects actually interactive (that is, do something when they are clicked on), but it is interesting
that XML makes the application design possible using ZERO Java coding, which is the intent of
extracting some of the application design functionality over to be done using XML markup.