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

Java Development

Reply
Developer
dbigham
Posts: 552
Registered: ‎04-01-2009
My Device: Z10, PlayBook
Accepted Solution

How to create a menu

I've taken a look at some of the sample applications, but the default behavior appears to be for the menu to be accessed by clicking the trackball. Questions:

 

1. How can a menu be constructed which is accessed via the menu button.

 

2. How can I get rid of the "Full Menu" menu item. 

 

3. How can I enable the "Back" and "Hangup" buttons so that they work as they do in all BlackBerry applications. (ie. The "Back" button keeps the program running and takes the user back to launcher screen, and the "Hangup" button does the same)

 

Thanks. 

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to create a menu

If you extend MainScreen, the menu key is already wired up for you. Just override makeMenu() and add your MenuItem objects to the menu.

 

If you extend FullScreen or other screen classes, you'll need to catch the MenuKey and call the menu yourself.

 

Clicking the trackball does not automatically invoke the menu - it depends on the screen context. This was also the defaul on older (4.10 and back)  OS levels.

 

The "back" and "hangup" buttons will also work if you extend MainScreen. "hangup" (redphone) will push your app to background, "back" will generally close the current screen.

 

You should look at the samples in a recent version of JDE  - all of this is covered.

 

Developer
dbigham
Posts: 552
Registered: ‎04-01-2009
My Device: Z10, PlayBook

Re: How to create a menu

[ Edited ]

Thanks for the direction. As it turns out, the reason the default buttons weren't working is that I had overridden keyDown, keyUp, etc, and I was returning "true" from each of those functions even when I wasn't overriding the default behavior.

 

Thanks for the tip about overridding the makeMenu function. That worked great. Note that I did a quick grep through the samples directory and didn't see any matches for "makeMenu". 

Message Edited by dbigham on 04-15-2009 10:54 PM
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to create a menu

I just did a search on the samples and found 57 occurrences of makeMenu()

 

:smileyhappy:

 

 

Developer
dbigham
Posts: 552
Registered: ‎04-01-2009
My Device: Z10, PlayBook

Re: How to create a menu

Am I looking in the wrong spot?

 

C:\Program Files\Research In Motion\BlackBerry JDE 4.6.0\samples\...

Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: How to create a menu

Hi,

 

 

Just search for menu or addMenuItem you will find code related to menu.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Regular Contributor
lyhoanghai
Posts: 71
Registered: ‎03-24-2010
My Device: 9550

Re: How to create a menu

To sum up:

1) If you extends MainScreen, just override makeMenu

 



	protected void makeMenu(Menu menu, int instance) {
		super.makeMenu(menu, instance);
		menu.add(new MenuItem("a",110,10) {			
			public void run() {
				
			}
		});
	}

 2) If you extends FullScreen, you MUST especify style DEFAULT_MENU and then override the make Menu

3) If you don't want default menu (e.g ShowKeyboard, Switch Application, Close), then don't call super.makeMenu

4) If you want higher level control of the menu: override onMenu() . This will be called when never user click on Menu button and normally (as in documentation), onMenu() will call makeMenu().

 

New Contributor
sonmailist
Posts: 2
Registered: ‎08-17-2011
My Device: Curve

Re: How to create a menu

How to hanlde "on click" menu, by its code..?

 

Many Thanks