BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   Im having trouble adding a menuitem to the mainscreen menu (http://www.blackberryforums.com/showthread.php?t=141322)

flameheels 07-21-2008 04:41 PM

Im having trouble adding a menuitem to the mainscreen menu
 
Im having difficulty adding a Menuitem to the main screen. Adding the other fields has been no problem. here is the code. Imports are included.

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

....

MenuItem men = new MenuItem("new item",40,40) {
public void run() {
// title.setText("text here");
}

};
add(men);


the error I get is:
C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\bin\HelloWorldtest.java:137: cannot find symbol
symbol : method add(net.rim.device.api.ui.MenuItem)

Dougsg38p 07-21-2008 04:52 PM

You don't add a menu item to your screen. You add a menu item to your menu. Look at overriding makeMenu() in the Screen class.

Ivanov 07-21-2008 05:09 PM

you can also use public void addMenuItem(MenuItem item) if you are not overriding makeMenu()

flameheels 07-21-2008 05:15 PM

Thank you.
Switching to addMenuItem worked.

Is it a better idea to override MakeMenu?

Ivanov 07-21-2008 05:53 PM

it depends...
if the menu items should be added "dynamicaly" (or the labels changed) depending on some state of the screen it is better to override makeMenu()

flameheels 07-22-2008 11:12 PM

thank you. I have not tried overiding MakeMenu yet, but I understand that to dynamically adding menuitems would best be done that way. I have found that I can change labels though the other way as well, as long as I declare the menuitems to be within the mainscreen class.


All times are GMT -5. The time now is 04:19 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.