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
Regular Contributor
Posts: 52
Registered: ‎06-24-2010
My Device: T-Mobile
My Carrier: 3
Accepted Solution

Question about menuItem

Hi all,

 

I have a problem to add a menu to all of the class that use the same MenuItem codes below: 

 

 

public class MenuCov extends MenuItem  {
   MenuItem Next;
MenuItem Cover;
    private FontFamily fontFam = Font.getDefault().getFontFamily();
  
   

public MenuCov() { super("test", 0, 0); try { fontFam = FontFamily.forName("BBCasual"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Cover = new MenuItem("Cover",110, 12) { public void run() { getApp().CoverCoy(); } }; Next = new MenuItem("Next",110, 12) { public void run() { getApp().MunifLanjut(); } }; } protected void makeContextMenu(ContextMenu contextMenu) { contextMenu.addItem(Cover); contextMenu.addItem(Next); } protected void makeMenu(Menu menu) { Field focus = UiApplication.getUiApplication().getActiveScreen().getLeafFieldWithFocus( ); if (focus != null) { ContextMenu contextMenu = focus.getContextMenu(); if (!contextMenu.isEmpty()) { menu.add(contextMenu); menu.addSeparator(); } }}

 

I call this class as follows :

 

		mc = new MenuCov();
		addMenuItem(mc);

 But the result than only  the text "test" in the constructor of the class is displayed, can someone help me how to create Menu Class that contains some MenuItem which is able be added on some other class that use this menus?

 

Thanks

 

Best Regards,

Bagir

 

Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Question about menuItem

 

a menuitem does not have the method makecontextmenu. you create this method in your class, but it is never executed. same with makemenu.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 52
Registered: ‎06-24-2010
My Device: T-Mobile
My Carrier: 3

Re: Question about menuItem

So what Change should I do to my code and How? Please Help Me.

Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Question about menuItem

 

i have no clue what you want to achieve.

 

to display a menu i usually take a mainscreen and overwrite makeMenu OR add menu items one by one.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 52
Registered: ‎06-24-2010
My Device: T-Mobile
My Carrier: 3

Re: Question about menuItem

I want to create some menu items that should be displayed in all pages of my application, I want that I don't need to code or recide it in all class that use this menuitem,  Can I use only one class that can be accessed by other class to display this menuItem at all pages? Please help me..

Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Question about menuItem

create a mainscreen. overwrite makemenu. let all other screens extend this screen.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 52
Registered: ‎06-24-2010
My Device: T-Mobile
My Carrier: 3

Re: Question about menuItem

How to override MakeMenu from the different class ?

Highlighted
Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Question about menuItem

makemenu is a method of mainscreen. if you use eclipse and have a mainscreen java file opened it should be proposed as a method to overwrite when you begin to type it.

by calling super.makemenu you add the default menu items (like close etc). you can add own ones calling addMenuItem inside the makemenu method.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 34
Registered: ‎09-24-2009
My Device: Not Specified

Re: Question about menuItem

First you create a MenuManager class where you add the common menu items(used in all screens).

Then from each screen override the makemenu() method as follows.

 

 

protected void makeMenu(Menu menu, int instance)
{
  menu.add(new MenuItem("Item-1", 1, 1)
  {
   public void run()
   {

      //Action

   }
  }); 

...
...

MenuManager.createMenu(menu);       
super.makeMenu(menu, instance);

}

 

 

"Item-1"  will be added to the common menus you already added in MenuManager.

 

 

Thanks,

Ravi