Structure of an XML Menu Resource File

First we'll look at an XML file with menu definitions (see Listing 5-20). All menu files start with the same high-level menu tag followed by a series of group tags. This group tag corresponds to the menu-item group we talked about at the beginning of the chapter. You can specify an ID for the group using the @+id approach. Each menu group will have a series of menu items with their menu-item IDs tied to symbolic names. You can refer to the Android SDK documentation for all the possible arguments for these XML tags.

Listing 5-20. An XML File with Menu Definitions

<menu xmlns:android=""> <!-- This group uses the default category. --> <group android:id="@+id/menuGroup_Main"> <item android:id="@+id/menu_testPick" android:orderInCategory="5" android:title="Test Pick" /> <item android:id="@+id/menu_testGetContent" android:orderInCategory="5" android:title="Test Get Content" /> <item android:id="@+id/menu_clear" android:orderInCategory="10" android:title="clear" /> <item android:id="@+id/menu_dial" android:orderInCategory="7" android:title="dial" /> <item android:id="@+id/menu_test" android:orderInCategory="4" android:title="@+string/test" /> <item android:id="@+id/menu_show_browser" android:orderInCategory="5" android:title="show browser" />

The menu XML file in Listing 5-20 has one group. Based on the resource ID definition @+id/menuGroup_main, this group will be automatically assigned a resource ID called menuGroup_ main in the resource ID file. Similarly, all the child menu items are allocated menu-item IDs based on their symbolic resource ID definitions in this XML file.

0 0

Post a comment