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
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810
Accepted Solution

Updating Menu or menu items

Hi.

 

I am having trouble changing the behaviour of menu items.

First I create a menu with x menu items.

Later on, on a specific event I want to change a menu item n or(as a fallback) I can recreate the whole menu with a new set of menu items.

 

What I tried is to use Menu.deleteAll() and Menu.deleteItem(int n) and both fail to remove any menu item.

I then thought, ok, maybe I cannot change already created menu/menu items. Maybe that's only available in makeMenu (although I didn't find any such instructions). But ! if i add a menu item to the same menu (even after the delete methods) the menu item gets on the menu and is correctly displayed.

Maybe we can add but cannot remove existing menu items ?

Now, what is going on?

 

All I want to do is to change a menuItem caption and its run() method (i.e., replace an existing menuItem).

 

Anyone has any ideas ?

 

(I am testing it on jde 4.5, on 8810 simulator)



"Listen carefully, I shall say this only once"
Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Updating Menu or menu items

I'm not sure I understand the question, but here goes:

 

To build menus, I override the makeMenu() method of my screen class. This method is called each and every time the menu key is pressed. Within this makeMenu() method, I place items on the menu (or not) as is appropriate for the application or screen context at the time the menu is created.

 

Consequently, there is no reason to remove items from a menu, so I have never tried to do so.

 

So, I guess I need to understand why are you trying to remove menu items?

 

Please use plain text.
Developer
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Updating Menu or menu items

Hi, sorry for the late reply, but I have closed the issue, partially.

 

My app has a lot of states, and in some states, certain menu items should be removed.

 

As it turns out, it is better to use MainScreen.removeMenuItem rather than Menu.DeleteAll().

 

The former approach works, the latter one doesn't :smileysad:

 

Thank you for your input and interest.



"Listen carefully, I shall say this only once"
Please use plain text.
New Developer
jkgrajesh
Posts: 10
Registered: ‎06-18-2009
My Device: Not Specified

Re: Updating Menu or menu items

Can anyone tell me .. how to add a new MENU with 4-5 menu items for a application on BB.?? Also, i want to navigate to a particular screen on click of any menu item.
Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Updating Menu or menu items

Something like this... In your MainScreen class. You check with some sample codes shipped with JDE.

 

 

protected void makeMenu(Menu menu, int instance) { menu.add(_fetchMenuItem1); menu.add(_fetchMenuItem2); .... menu.add(_fetchMenuItem5); } private MenuItem _fetchMenuItem1 = new MenuItem("Fetch1" , 100, 10) { public void run() { // code here } }; private MenuItem _fetchMenuItem2 = new MenuItem("Fetch2" , 105, 10) { public void run() { // code here } };

 

 To Navigate from Screen to Sceen, you have to push the Screen to the Display stack using pushScreen method. popScreen method to remove the screen from Display.

 

There are good number of threads discussed.

 


Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
New Developer
commend
Posts: 3
Registered: ‎08-24-2009
My Device: Not Specified

Re: Updating Menu or menu items

Hi,

 

I´m really new in BlackBerry development. I crated a special Menu with certain Menu Items.

 

Now I want to add a icons to the menuItems. If you have a look at the standard Menu (manage connections) then you can see a colored status icon for connection-status(green check mark or red cross).

 

Please Help, how do I get such icons added to the MenuItems?

 

kind regards!

 

 

Please use plain text.