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
vishalkheterpal
Posts: 134
Registered: ‎01-11-2011
My Device: curve
Accepted Solution

How to show menu on click event on my button

I need to show menu on clickevent on my button and menuitems will be different for the different buttons.How to do this.

I have override makemenu method like this.

 

	protected void makeMenu(Menu menu, int instance) {
		super.makeMenu(menu, instance);
		menu.deleteAll();

		if (categoryFlag) {
		for (int i = 0; i < list.size(); i++)
                {			
			menu.add(newMenuItem(list[i], 110,10+i) {
					public void run() {
					callMeWithScrollField(0);
					} 
					}
					);
		}
			menu.setOrigin(categories.getExtent().x, Display.getHeight());
		} else if (optionFlag) {

			menu.add(subscriptionMenu);
			menu.add(reOrderMenu);
			menu.add(aboutMenu);
			menu.add(feedBack);
			menu.setOrigin(option.getExtent().x, Display.getHeight());
		}

		menu.show();

	}

 But it shows menu twice.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to show menu on click event on my button

[ Edited ]

Are the two menus identical?

 

Do you need the

menu.show();

line?

 

Why bother calling super.makeMenu if you are just going to ignore anything it adds?

Please use plain text.
New Developer
vishalkheterpal
Posts: 134
Registered: ‎01-11-2011
My Device: curve

Re: How to show menu on click event on my button

No both the menus are different.

I am not sure on menu.show();But if i not call this menu doesnot appears.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to show menu on click event on my button

remove the super.makeMenu(). 

Please use plain text.
New Developer
vishalkheterpal
Posts: 134
Registered: ‎01-11-2011
My Device: curve

Re: How to show menu on click event on my button

I did it.But even now on 9860 simulator menu comes twice.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to show menu on click event on my button

Sorry my mistake.

 

You will not be able to do what you want using makeMenu.  Instead you will have to override onMenu() for the MainScreen.  Here is a sample:

 

    public boolean onMenu(int instance) {
  // super.makeMenu(menu, instance);
  Menu newMenu = new Menu();
     newMenu.add(new MenuItem("Test", 110,10) {
   public void run() {
   }
   }
   );
  
     newMenu.show();
     return true;
    }

 

Please use plain text.