Right, got it. So to create a submenu, we can do this (within the top-
level menu element):

<item android:id="@+id/upload" android:icon="@drawable/ic_menu_upload"
android:title="Upload">
    <menu>
        <item android:id="@+id/facebook" android:title="Facebook" />
        <item android:id="@+id/myspace"android:title="MySpace" />
    </menu>
</item>

The pattern is <item> - <menu> - <item>.

On Mar 31, 10:42 am, Glen Humphrey <[email protected]>
wrote:
> In a menu XML layout, there are three valid elements: <menu>, <group>
> and <item>. The item and group elements must be children of a menu,
> but item elements may also be the children of a group, and another
> menu element may be the child of an item (to create a Submenu). Of
> course, the root node of any file must be a menu element.
>
> On Mar 30, 7:14 pm, suzannea <[email protected]> wrote:
>
>
>
> > Does anyone have an example of adding a submenu to an options menu in
> > XML? I'm interested in doing something like this Java example (from
> > the Google developer guide, Creating Menus):
>
> > public boolean onCreateOptionsMenu(Menu menu) {
> >   boolean result = super.onCreateOptionsMenu(menu);
>
> >   SubMenu fileMenu = menu.addSubMenu("File");
> >   SubMenu editMenu = menu.addSubMenu("Edit");
> >   fileMenu.add("new");
> >   fileMenu.add("open");
> >   fileMenu.add("save");
> >   editMenu.add("undo");
> >   editMenu.add("redo");
>
> >   return result;
>
> > }
>
> > However, I designed my options menu in XML, using the visual layout
> > editor. I tried putting several items within a group, like this:
>
> > <group android:enabled="true" android:visible="true"
> > android:menuCategory="container" android:id="@+id/update_group">
> >         <item android:title="Facebook" android:id="@+id/facebook"></item>
> >         <item android:title="MySpace" android:id="@+id/myspace"></item>
> > </group>
>
> > But instead of getting a submenu, I got additional items on the
> > options menu, which created an extended menu.- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to