Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
khihdartop
Posts: 16
Registered: ‎08-24-2012
My Device: 9800
My Carrier: azer

Create sub menu for a BlackBerry

I want to Create sub menu for a BB application when I click on menu item it shows

Option 1 Option 2 Option 3 

When I click on option 3 it should display

1 2 3 

as sub menu items

using javascript

Please use plain text.
Developer
BrajeshSanodiya
Posts: 134
Registered: ‎08-03-2011
My Device: torch, Z10
My Carrier: Vodafone, Airtel

Re: Create sub menu for a BlackBerry

check this.

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Adding-Menu-Items-using-the-Blac...
-----------------------------------------------------------------------
"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
-----------------------------------------------------------------------
Please use plain text.
Contributor
khihdartop
Posts: 16
Registered: ‎08-24-2012
My Device: 9800
My Carrier: azer

Re: Create sub menu for a BlackBerry

Thinks

 

Yes I have see this but it's to create a menu not a sub menu

Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Create sub menu for a BlackBerry

[ Edited ]

welcome to the support forums.

 

since 6.0 you can use
http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/menu/SubMenu.html to add submenus.
on 5.0 or lower you would have to code your own menu

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
Kiran_Snist
Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

Re: Create sub menu for a BlackBerry

Try this:

public class SampleScreen extends MainScreen implements FieldChangeListener
{
	SubMenu statusSubMenu,openSubMenu;
	ButtonField buttonField,click;
	private MenuItem available = new MenuItem(new StringProvider("Available"), 100, 1)
    {
        public void run()
        {
            Dialog.inform("I'm available");
        }
    };
    
    private MenuItem unAvailable = new MenuItem(new StringProvider("Unavailable"), 200, 2)
    {
        public void run()
        {
            Dialog.inform("I'm unavailable");
        }
    };
    
	private MenuItem saveMenu = new MenuItem(new StringProvider("Save"), 100, 1)
    {
        public void run()
        {
            Dialog.inform("I'm Save");
        }
    };
    
    private MenuItem saveAsMenu = new MenuItem(new StringProvider("Save As"), 200, 2)
    {
        public void run()
        {
            Dialog.inform("I'm Save As");
        }
    };
    
    public SampleScreen()
    {
      setTitle("Create Submenu Sample");     
      createGUI();
    }
    private void createGUI() 
    {
    	add(new RichTextField("Create a submenu",Field.FOCUSABLE));
    	buttonField=new ButtonField("Check");
    	buttonField.setChangeListener(this);
    	add(buttonField);
    	
    	click=new ButtonField("click");
    	click.setChangeListener(this);
    	add(click);
    	
    	statusSubMenu = new SubMenu(null,"My Status",300,3);
    	statusSubMenu.add(available);
    	statusSubMenu.add(unAvailable);
    	
    	openSubMenu = new SubMenu(null,"Open",400,4);
    	openSubMenu.add(saveMenu);
    	openSubMenu.add(saveAsMenu);
	}
	
    protected void makeMenu( Menu menu, int instance )
    {
        menu.add(statusSubMenu);
        menu.add(openSubMenu);
        super.makeMenu(menu, instance);
    }
	public void fieldChanged(Field field, int context) 
	{
		if(field==buttonField)
		{
			isHavingSubMenu(statusSubMenu,available);
		}
		else if(field==click)
		{
			isHavingSubMenu(openSubMenu,saveAsMenu);
		}
	}
	
	public void isHavingSubMenu(SubMenu subMenu, MenuItem menuItem)
	{	
		Screen screen=Ui.getUiEngine().getActiveScreen();
		Menu menu=screen.getMenu(0);		
		for(int i=0;i<menu.getSize();i++)
		{
//			System.out.println("\n=========== Menu ==============="+menu.getItem(i).toString()+"======"+subMenu.getMenuItem().toString());
			
			if(menu.getItem(i).toString().equalsIgnoreCase(subMenu.getMenuItem().toString()))
			{	
				
				for(int j=0;j<subMenu.getSize();j++)
				{
					if(subMenu.getItem(j).toString().equalsIgnoreCase(menuItem.toString()))
					{
						System.out.println("\n========== Sub Menu ================"+subMenu.getItem(j).toString());
						subMenu.getItem(j).run();
					}					
				}
			}		
		}			
	}
}

 

Please use plain text.
Contributor
khihdartop
Posts: 16
Registered: ‎08-24-2012
My Device: 9800
My Carrier: azer

Re: Create sub menu for a BlackBerry

But i want to do with javascript not with java .think's

Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Create sub menu for a BlackBerry

best to post the question in the webworks forum then, i'll ask a moderator to move it.
(you posted in the java forum, usually it's for java)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.