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: 367
Registered: ‎11-25-2009
My Device: Not Specified
Accepted Solution

Need help with ContextMenu of CustomEditField

[ Edited ]

Hi Everyone,

 

I created a CustomEditField which, when I type past the width of the EditField, it will not go to a new line, but rather "keep going" on the same line (and hide the text before it).

 

I am looking to correctly override makeContextMenu so that when I click either the Menu key OR click on the trackball (with the CustomEditField in focus), a ContextMenu will come up with just a "Search" Item inside of it. (Similar to "Send" in the BBM text field).

 

I would really appreciate any help, below is my current code:

 

 

public class CustomEditField extends VerticalFieldManager {

private int managerWidth;
private int managerHeight;
private EditField editField;

public CustomEditField(final String label, int width) {

super(Manager.NO_VERTICAL_SCROLL);
managerWidth = width;

VerticalFieldManager vfm = new VerticalFieldManager(
Manager.VERTICAL_SCROLL);

editField = new EditField() {
public void paint(Graphics g) {
getManager().invalidate();
super.paint(g);
}

protected void onFocus(int direction) {
if (getText().equals("") || getText().equals(label)) {
setText("");
}
}

protected void onUnfocus() {
if (getText().equals(label) || getText().equals("")) {
setText(label);
}
}
};

editField.setText(label);
vfm.add(editField);
add(vfm);
}

public void paint(Graphics g) {
super.paint(g);

int oldColor = Color.GRAY;
// int oldAlpha = g.getGlobalAlpha();

// g.setGlobalAlpha(0x88);
g.setBackgroundColor(0x00EF3825);
g.setColor(Color.BLACK);
g.fillRoundRect(0, 0, getWidth(), getHeight(), 8, 8);
g.setColor(oldColor);
// g.setGlobalAlpha(oldAlpha);
super.paint(g);
}

public void sublayout(int width, int height) {

if (managerWidth == 0) {
managerWidth = width;
}
if (managerHeight == 0) {
managerHeight = height;
}
super.sublayout(managerWidth, getPreferredHeight());
setExtent(managerWidth, getPreferredHeight());
}

class ContextMenuItem extends MenuItem {
public ContextMenuItem() {
super("Search", 20, 10);
}

public void run() {
// search();
}
}

}

 

Thanks!

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: Need help with ContextMenu of CustomEditField

Oops,

 

Here is my code for my ContextMenu...

 

 

protected void makeContextMenu(ContextMenu menu) {
	super.makeContextMenu(menu);
	menu.addItem(new ContextMenuItem());
}

 

I have this overriding for EditField. What this currently does is add "Search" into the regular Menu (when you click the Menu Key), but it does nothing to the ContextMenu that comes up in the middle of the screen when you click the trackball inside of the EditField.

 

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: Need help with ContextMenu of CustomEditField

Solved with the following code in MainScreen:

 

 

	public void makeMenu(Menu menu, int instance) {
		super.makeMenu(menu, instance);
		// add these items to the full menu
		if (instance == Menu.INSTANCE_DEFAULT) {
			menu.add(new SearchMenuItem());
			menu.add(new BrowseMenuItem());
			menu.add(new QueuesMenuItem());
		}
		if (instance == Menu.INSTANCE_CONTEXT) {
			menu.add(new ContextMenuItem());
		}

	}