Creating submenu dynamically

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Creating submenu dynamically

Postby finucas » Fri Jul 16, 2010 7:35 pm

Hi i having an issue figuring out how to create a submenu and affix it to a menu item.

I can do this easily enough in my menu.xml file and all works well
but the submenu items are not known at run-time so i cannot do it this way,

for demonstration purposes heres a menu.xml file
consisting of two menu items

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/add_menu"
android:icon="@drawable/logo"
android:title="@string/add_new">
</item>
<item android:id="@+id/cancel_menu"
android:icon="@drawable/remove_item"
android:title="@string/remove">
</item>
</menu>


Now in my main code how would i go about adding a submenu for say add_menu?

the thing is i know how to add a SubMenu in the code w/o using xml menu file also
but i dont know how to create one when i have the menu defined in xml?

Maybe do i have to give the menu an ID in the xml,
then addSubMenu in the java code to that specific ID?

Please help i have been searching for hours now.
finucas
Freshman
Freshman
 
Posts: 6
Joined: Tue Jul 13, 2010 4:26 pm

Top

Re: Creating submenu dynamically

Postby andreslr » Sat Mar 12, 2011 10:35 am

Did you solve this? I'm trying to achieve the same.
andreslr
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed Jul 01, 2009 6:44 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests