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
New Developer
black_berry
Posts: 54
Registered: ‎11-12-2008
My Device: Bold 9800 or Storm 3 whichever hits Verizon first.
My Carrier: Verizon
Accepted Solution

Besides being lost how do I

Hello BB experts.

I am trying to figure out how to add the following menu to the menu that appears when a user clicks on Menu button on the BB device.

 

Menu menu = UiApplication.getUiApplication().getActiveScreen().getMenu(0);

menu.add(
mi_moveActionDown);

menu.add(mi_moveActionUp);menu.add(

mi_deleteAction);

menu.addSeparator();

menu.add(
mi_close);

menu.addSeparator();

menu.show();

this.makeMenu(menu, 0);

 

Please tell me how to do this.

PS. I have no background in handheld devices :smileysad:

Thank you all for your support
black_berry
Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Besides being lost how do I

The general method to do this is to override makeMenu() in your MainScreen class.

 

protected void makeMenu(Menu menu,
                        int instance)

 

The menu is object is passed to the method, you add your items here.

Please use plain text.
New Developer
black_berry
Posts: 54
Registered: ‎11-12-2008
My Device: Bold 9800 or Storm 3 whichever hits Verizon first.
My Carrier: Verizon

Re: Besides being lost how do I

I changed the this.makeMenu(menu, 0); to super.makeMenu(menu, 0);

 

Also the class I am in extends MainScreen.

 

Nothing shows up so my next question is, can you at any time change the display of what is in the menu?

Say if I make 2 methods A and B. Each method constructs its own set of menu options and then calls super.MakeMenu(...); Would this work? can I just repopulate the menu as I want whenever I want?

Thank you all for your support
black_berry
Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Besides being lost how do I

You must override makeMenu() in your Screen class.

 

The UI framework calls makeMenu and passes the existing Menu object to it, so that you can add your items.

 

so...

protected void makeMenu(Menu menu, int instance) { menu.add(myMenuItem); }

 

 

 

Please use plain text.
New Developer
black_berry
Posts: 54
Registered: ‎11-12-2008
My Device: Bold 9800 or Storm 3 whichever hits Verizon first.
My Carrier: Verizon

Re: Besides being lost how do I

So when you refer to my "Screen" class, I am assuming that you mean the MainScreen that my class extends. Am I correct on this assumption?

 

And yes, I'm unzipping all of the sample code that BB provides since I have no idea really how to really interface with the BB devices in hopes to gain some serious insight.

Thank you all for your support
black_berry
Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Besides being lost how do I

I assume you are subclassing MainScreen, right?

 

If so, then yes, you have to "override" the makeMenu method so that the framework calls YOUR method rather than the default method defined in the MainScreen class.

 

If you do not understand the concept of "override", then I suggest you read some basic Java tutorial material. You will also find many different examples of adding a menu item to a MainScreen in the sample code.

 

Please use plain text.
New Developer
black_berry
Posts: 54
Registered: ‎11-12-2008
My Device: Bold 9800 or Storm 3 whichever hits Verizon first.
My Carrier: Verizon

Re: Besides being lost how do I

Yes I am subclassing the Mainscreen and i am familiar with Java programming but have NEVER done any GUI with Java before so the whole implementation is foreign to me.

 

Frusterating being thrown into something like this and deadlines that provide no time to spend a week learning how to do anything in interfaces but instead feel like im just wasting time guessing and trying different things as i just dont have time to research.

 

Funny how mgmt always seems to be ok with the idea of wasting time in doing things wrong rather than to alot for time for us to learn to do it right.

Thank you all for your support
black_berry
Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Besides being lost how do I

Sorry, wasn't trying to call you "stupid".

 

I searched the 4.2 samples directory and found 62 occurrences om "makeMenu()", so it's in just about every single program.

 

makeMenu() is called by the framework every time your user clicks on the Menu key - this allows you to populate the menu in a "context aware" manner - so you can add only the menu items that are appropriate given the current state of the screen.

 

What kind of program you are trying to write? You may be able to use one of the samples as a starting point.

Please use plain text.
Administrator
MSohm
Posts: 14,296
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Besides being lost how do I

This sample may help you.

 

How To - Distinguish between a full menu and a primary actions menu
Article Number: DB-00565

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800608/...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
black_berry
Posts: 54
Registered: ‎11-12-2008
My Device: Bold 9800 or Storm 3 whichever hits Verizon first.
My Carrier: Verizon

Re: Besides being lost how do I

RexDoug, no offense taken. I can admit that I am ignorant to the world of HandHelds thats why I am asking all these questions no matter how simple they may seem so some because everyone at some point did not know something. It's like the days of old what do I do with a <table> tag? :smileyhappy:

 

I appreciate the information that you have provided.

Thank you all for your support
black_berry
Please use plain text.