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
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Rephrased Question: Is It Possible to Refer To The Default Menu of MainScreen in Code?

I'm working with an app that uses a MainScreen that uses super(DEFAULT_MENU | DEFAULT_CLOSE) so a menu with default options is created.

 

I'm trying to keep that menu visible when a specific MenuItem (one that I added) is selected.  Is it possible to get a reference for the default MainScreen menu that I can use in code to keep it visible?

 

I've searched the docs for MainScreen, Screen, MenuItem and Menu and I've tried several things in code with no success.  Here's what I've tried so far:

 

 

// each line represents a separate attempt to get the default menu

// first attempt
Menu menu = getMenu(0)

// second attempt
Menu menu = getMenu(INSTANCE_DEFAULT)

// third attempt
Long dm = new Long(DEFAULT_MENU);
Double ddm = new Double(dm.doubleValue());
int defaultMenu = ddm.intValue();
Menu menu = getMenu(defaultMenu);

 

Any help is greatly appreciated

 

 

 

BlackBerry Development Advisor
Posts: 15,727
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Rephrased Question: Is It Possible to Refer To The Default Menu of MainScreen in Code?

Are you trying to get an instance of the MenuItem the user selects?  Or do you want to redisplay the menu after the user has clicked on your MenuItem?  Or are you trying to customize what is shown on the menu each time it is displayed?

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
Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Rephrased Question: Is It Possible to Refer To The Default Menu of MainScreen in Code?

[ Edited ]

I want to keep the menu that contains the MenuItem that the user clicks on, visible.

 

Basically, what happens now is, when I click on the MenuItem, the menu closes, then my custom submenu appears.  I'd like the menu to stay visible...in the same way it would when a submenu appears from a main menu in a RIM application.

 

I'm using RIM API 4.6.0 and coding for my Blackberry Bold.  On my Bold, in the WiFi settings, the main menu has a WiFi Tools menu item has a submenu.  I'm trying to duplicate that behavior.

 

 

The funny thing is, the submenu solution RIM coded is sort of clumsy looking.  When it appears in the WiFi tools menu, it partially covers the original menu.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Rephrased Question: Is It Possible to Refer To The Default Menu of MainScreen in Code?

What do you use to push your menu screen?  I presume invokeLater?

 

If you do a pushModal or an invokeAndWait in the menu item's run() method, I think the standard menu is still displayed, I don't think it gets dismissed till after the run() method has completed.  So try one of these, it might work for you. 

 

I actually don't mind the WiFi submenu being put over the top of the original menu.

Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Rephrased Question: Is It Possible to Refer To The Default Menu of MainScreen in Code?

 


peter_strange wrote:

What do you use to push your menu screen?  I presume invokeLater?

 

If you do a pushModal or an invokeAndWait in the menu item's run() method, I think the standard menu is still displayed, I don't think it gets dismissed till after the run() method has completed.  So try one of these, it might work for you. 

 

I actually don't mind the WiFi submenu being put over the top of the original menu.


 

 

Oh, I don't mind it either, but I still think it's kinda clumsy looking.  Maybe "clumsy" isn't the word...not sure how to put it...it doesn't flow like a submenu?

 

Right now I'm using pushScreen(), since the MainScreen is in the main application thread.  I'll try pushModal and see what happens...though I'm going to kick myself if the solution is that simple.

Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Rephrased Question: Is It Possible to Refer To The Default Menu of MainScreen in Code?

Unfortunately, using pushModalScreen() did not work.  The behavior is still the same.  Clicking the MenuItem invokes the custom submenu, but it closes the first, original menu.

 

Here's the code for

 

the MenuItem that invokes the submenu:

 

 

 post = new MenuItem("post", 100, 0)
    {
        public void run()
        {
            UiApplication.getUiApplication().pushModalScreen(psm);
        }
    };

 

 

the PopupScreen that contains the ObjectListField submenu items:

 

 

 psm = new PopupScreen(new VerticalFieldManager())
    {
        public int getPreferredWidth()
        {
            int prefWidth = subMenu.getContentWidth();
            return prefWidth;
        }
    };

 

 

the ObjectListField submenu items:

 

 

    subMenu = new ObjectListField();
    subMenu.insert(0, postTxt);
    subMenu.insert(1, postPic);
    subMenu.insert(2, postQuote);
    subMenu.insert(3, postLink);
    subMenu.insert(4, postChat);
    subMenu.insert(5, postAud);
    subMenu.insert(6, postVid);

 

 

Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Rephrased Question: Is It Possible to Refer To The Default Menu of MainScreen in Code?

Giving post a bump to the top to request additional help.

 

Right now, pushModalScreen() is not having the desired effect (keeping default MainScreen menu open while custom submenu isdisplayed.  I'm going to see if there is any way to somehow override the MenuItem or default Menu methods to make this work, but anyone who has an alternate solution, please chime in.

 

Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Rephrased Question: Is It Possible to Refer To The Default Menu of MainScreen in Code?

Still working on this, so any help appreciated.

 

Working within MenuItem.run() won't work.  Right now I'm experimenting with overriding onMenu().

 

My issue is not being able to keep the MainScreen menu open while my custom PopupScreen subMenu is displayed.

Highlighted
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Rephrased Question: Is It Possible to Refer To The Default Menu of MainScreen in Code?

I have not completely read the entire post, but i do not think this would be possible. Seeing as how the MenuItem uses the run method, it probably overrides Runnable and is called using a invokeLater method by the menu. This means the menu would be closed as soon as the MenuItem is invoked. You will probably need to make a custom Menu class that calls invokeAndWait so that the screen displays until the MenuItem returns.