BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-15-2010, 03:11 AM   #1 (permalink)
New Member
 
Join Date: Apr 2010
Model: 8310
PIN: N/A
Carrier: 4.1.0
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default ContextMenu : unable to achieve on JDE 4.1 and below : some items are displayed twice

Please Login to Remove!

Hi all,

I am working on the Menu and Context Menu currently.For an edit field,I want to add a menu item "Search" on its context menu.I created a custom edit field, and over-rided the makeContextMenu() to add the "Search" item. In my Screen class, i over-rided the makeMenu() and handled it as below :

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

		if (instance == Menu.INSTANCE_DEFAULT) {

			menu.add(new MenuItem("Login", 20, 10) {
				public void run() {
					login();
				}
			});

		} else if (instance == Menu.INSTANCE_CONTEXT) {
			// context menu handling :

			Field focussedField = UiApplication.getUiApplication()
					.getActiveScreen().getLeafFieldWithFocus();
			if (focussedField != null) {
				ContextMenu cm = focussedField.getContextMenu();
				if (!cm.isEmpty()) {
					menu.add(cm);
				}
			}
		}
	}
My customEditField looks like :

Code:
protected void makeContextMenu(ContextMenu contextMenu) {
		super.makeContextMenu(contextMenu);
		contextMenu.addItem(new MenuItem("MyeditField 1", 10, 2) {

			public void run() {
			}

		});
		
		
	}
I got this solution from the BLB support forum, and it works fine for JDE 4.2 and above.

However, I am trying to achieve the same on JDE 4.1 and below also.

I tried a simple workaround, by replacing the Menu.INSTANCE_CONTEXT and Menu.INSTANCE_DEFAULT with thier actual values since these constants have been included only since JDE 4.2

I was able to achieve the context menu properly, but when i try to paste some selected and copied text, I get the "Paste" item twice in my context menu, although it is displayed only once in the main menu.

I suppose I have to include handling for Menu.INSTANCE_CONTEXT_SELECTION also, but am clueless about how to handle it..

Also, if anyone can suggest a cleaner way of achieving it in JDE 4.1 or below, it would be really great..

Thanks..
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.