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: 54
Registered: ‎11-12-2009
My Device: Not Specified

Remove only the "Close" menu item from Menu

Hi all,

 

I have found several posts on the similar issue, but I am not completely sorted though.

 

I would like to remove only the "close" menu item from the main as well as the context menu.I found a solution from the following KB article :

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800256/...

 

I over-rided the makeMenu() and removed the call to the super class, thereby avoiding the addition of "close".

 

However, this also stops the prefabricated menu item "Full Menu" from being displayed from my context menu.I want only the close to disappear, all others being the same.

 

I also came across an api on Screen viz setDefaultClose(boolean). I tried over-riding this for my MainScreen instance with a false value indicating that the "close" item should not be displayed.However, this does not seem to be working.

 

Please help if anyone has faced a similar issue,

 

Thanks,

Hiral

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

Re: Remove only the "Close" menu item from Menu

You can override the makeMenu method as is shown within that KB article.  However, instead of removing the call to super.makeMenu, leave it in but modify the menu that is passed into makeMenu before calling super.makeMenu.  You can loop through all items of the menu until you find Close and then delete it.  So use Menu.getSize to find out how many menu items there are, retrieve each one using Menu.getItem and then use Menu.deleteItem to remove the close MenuItem when found.

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
Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT

Re: Remove only the "Close" menu item from Menu

protected void makeMenu(Menu menu, int instance) {
ContextMenu contextMenu = ContextMenu.getInstance();
contextMenu.setTarget(this);
contextMenu.clear();
this.makeContextMenu(contextMenu);
menu.deleteAll();
menu.add(contextMenu);
}

public void makeContextMenu(ContextMenu contextMenu) {
contextMenu.addItem(_startMeasurement);
}

-Fight with BB10