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: 106
Registered: ‎06-18-2009
My Device: Bold

Re: Preventing context menu from appearing on click?

okay try this:

 

protected boolean navigationClick(int status, int time) 
{
         fieldChangeNotify(0);
         return true;
}

 

 

You can then implement FieldChangeListener in your Screen and handle the clicks within your screen (or pass to Controller).

 

This works for me.  You can change the 'context' paramter to any digit.

----
If this helped you, press the thumbs up button (on the far right - '+' thumb icon)
If this post solved the issue, click "Accept as Solution"
Developer
Posts: 65
Registered: ‎01-05-2010
My Device: Not Specified

Re: Preventing context menu from appearing on click?

Ok, will try this.
Developer
Posts: 65
Registered: ‎01-05-2010
My Device: Not Specified

Re: Preventing context menu from appearing on click?

[ Edited ]

@filiussoft I have tried your suggestion, and the behaviour is the same as before.

 

When I press the ListField (F) the press is actioned, a new manager (E) is displayed in its container (D) replacing the original manager (E) that contained the ListField (F), THEN the full menu appears over the new content. i.e. steps 6 through 9 from my earlier post.

 

Expanding on what is happening during handling the click, I am sort of doing this (though a lot more complicated in reality)

 

F.onclick() { // called ultimately from F.navigationClick()

  D.deleteAll();

  E = new CustomManager();

  D.add(E);

  F = new CustomField();

  E.add(F)

}

 

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: Preventing context menu from appearing on click?

The last thing to do is make sure the code in your navigationClick has no errors. If it does the menu will come up no matter what.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Developer
Posts: 65
Registered: ‎01-05-2010
My Device: Not Specified

Re: Preventing context menu from appearing on click?

Do you mean exceptions?  I am not getting a breakpoint in the debugger and the code is executing and doing its stuff, so I would think that classifies as no errors.


I can only imagine the is because I am removing the manager/field that gets the click event and adding new manager.

 

Nothing I have tried so far has solved the problem, except NOT doing anything during the click event, then I don't see the menu.

Developer
Posts: 190
Registered: ‎10-22-2009
My Device: Blackberry Torch

Re: Preventing context menu from appearing on click?

following thread might be helpful:


http://supportforums.blackberry.com/t5/Java-Development/blackberry-UI-event-delegation-model/m-p/460...

 

 

 

 

-----------------------------------------------------------------------------------
Please mark posts as solved if you found a solution. Press the kudos button to thank the user who helped you.
Developer
Posts: 65
Registered: ‎01-05-2010
My Device: Not Specified

Re: Preventing context menu from appearing on click?

[ Edited ]

Which basically says, don't override navigateClick() and it propagates down from screen through manager to field, and when you consume it return true. Which is exactly what I am doing. However the full menu appears after the new manager has been added to its container which replaced the manager containing the field that generated the event. If I remove the code from navigationClick() so it just consumes the click and doesn't do anything else, the menu is not displayed. So it seems linked to, the replacing of the manager and ultimately the field that had focus when the event fires, as if that upsets the whole "return true to consume" process.

 

I will see if I can produce a simple test case that replicates the problem and post the code.

Developer
Posts: 65
Registered: ‎01-05-2010
My Device: Not Specified

Re: Preventing context menu from appearing on click?

[ Edited ]

Ok... a small update on this problem. I think I have just proved my theory that its because I remove the manager with the field the event is for from the display during the event. Here is my modified Custom ListField

 

public class TableField extends ListField {
	protected boolean keyChar(char character, int status, int time) {  
	    if (character == Keypad.KEY_ENTER) {  
	        fieldChangeNotify(0);  
	        return true;  
	    }  
	    return super.keyChar(character, status, time);  
	}  		  
	protected boolean navigationClick(int status, int time) {  
	    fieldChangeNotify(0);  
	    return true;  
	}	
	protected boolean navigationUnclick(int status, int time) {
		return true;
	}
}

Very simple, standard stuff.  navigationUnclick() is not getting called and is superfluous to requirements.

 

The manager that contains this field does the following, first in the constructor after creating the list field, I set the change listener to be the manager itself.

 

	table.setChangeListener(this);

 then in the fieldChanged() method (while testing this issue) I do nothing at all.

 

public void fieldChanged(Field field, int context) {
	if (field == table) {
		// onclick(table.getSelectedIndex());
	}
}

Note that the body of the method is commented out, i.e. a click does nothing.

 

In this state, when I press/click the list field row, nothing happens, and the full menu does NOT appear.  This is what you would expect as navigationClick() returns true.

 

Now, if I change the fiedlChanged method to remove the manager containing the list field from its parent (which emulates part of what onclick() does in my code), as follows:

 

public void fieldChanged(Field field, int context) {
	if (field == table) {
		// TEST
		Manager parent = getManager();
		parent.deleteAll();

		// onclick(table.getSelectedIndex());
	}
}

Now, when I press/click a row in the ListField, the list and its manager disappear from view (correct) but then the full menu is displayed.

 

So it seems the act of removing the manager from the display during the event prevents the true return from navigationClick() from consuming the event.

 

Just need to work out a way around it now.

Developer
Posts: 65
Registered: ‎01-05-2010
My Device: Not Specified

Re: Preventing context menu from appearing on click?

[ Edited ]

I tried using invokeLater() to defer the removal of the manager but it still shows the menu.

 

public void fieldChanged(Field field, int context) {
	if (field == table) {
		// TEST
		App.runOnMainThread(new Runnable() {
			public void run() {
				Manager parent = getManager();
				parent.deleteAll();
			}
		});

		// onclick(table.getSelectedIndex());
	}
}

App.runOnMainThread() is just a convenient wrapper for invokeLater().

 

Developer
Posts: 65
Registered: ‎01-05-2010
My Device: Not Specified

Re: Preventing context menu from appearing on click?

[ Edited ]

Well, I have a possible workaround for this problem, a variation of the previous attempt to work around it.  If I use invokeLater(runnable, 100, false) to run the handler for the click event, then the menu does not display.

 

public void fieldChanged(Field field, int context) {
	if (field == table) {
		App.runOnMainThreadAfter(100, new Runnable() {
			public void run() {
				onclick(table.getSelectedIndex());
			}
		});
	}
}

 

App.runOnMainThreadAfter() being a simple wrapper for invokeLater(runnable, ms, false).

 

Question is, can I rely on this behaviour.  What is the smallest ms that will work reliably?  1ms?  Is it the fact that I add a delay which allows the handleClick() event to complete before action is taken?