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 Contributor
Posts: 3
Registered: ‎05-18-2011
My Device: Torch 9800
My Carrier: AT&T

Context menu won't go away with ButtonField (example included)

[ Edited ]

I'm trying to create a ButtonField that I can hold down and release without the context menu popping up. I have had no luck in this endeavor.

 

The behavior seems to be:

 

* Holding down the button for < 1 sec fires off navigationClick() and navigationUnclick().

 

* Holding down the button for > 1 sec fires off navigationClick(), but then pops up the context menu. navigationUnclick() never gets called.

 

Would appreciate an idea of how to solve this problem, or if I should cut bait and roll a custom control. Sample code is below. Note I am using the CONSUME_CLICK style and returning 'true' from navigationxxx() methods.

 

Platform tested is Torch 9800 6.0.0.526 (bundle 2342) using Java Eclipse plugin 1.3.0 for OSX.

 

 

 

import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.util.StringProvider;

public class TestButtonScreen extends MainScreen
{
	public TestButtonScreen()
	{
		setTitle("Test ButtonField Popup Menus");
		
		MenuItem testMenuItem = new MenuItem(new StringProvider("Test Menu Item"), 0x10110, 10)
		{
			public void run()
			{
				Dialog.alert("Foo.");
			}
		};
		addMenuItem(testMenuItem);
		add(new SubclassedButton());
	}
	
	class SubclassedButton extends ButtonField 
	{
		public SubclassedButton()
		{
			super("PRESS THIS", ButtonField.CONSUME_CLICK);
		}

		protected boolean navigationClick(int status, int time)
		{
			setTitle("BUTTON PRESSED");
			return true;
		}

		protected boolean navigationUnclick(int status, int time)
		{
			setTitle("Press the Button");
			return true;
		}
	}
}

 

 

 

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Context menu won't go away with ButtonField (example included)

create the button with CONSUME_CLICK style and use a fieldchangelistener to get it's click
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 202
Registered: ‎04-19-2011
My Device: Blackberry Bold 9780
My Carrier: TAM

Re: Context menu won't go away with ButtonField (example included)

i think simon is right...

implement your screen with fieldChangeListener

then in your screen constructor, use this...

 

 

button1 = new ButtonField("it's not pressed yet", ButtonField.CONSUME_CLICK);
button1.setChangeListener(this);

 

 

after that use this void, use this..

 

public void fieldChanged(Field field, int context) {
  if (field == button1)
  {
     button1.setLabel("it's Pressed");
  }
}

 

 

 

New Contributor
Posts: 3
Registered: ‎05-18-2011
My Device: Torch 9800
My Carrier: AT&T

Re: Context menu won't go away with ButtonField (example included)

As described, I am creating the button with CONSUME_CLICK. I cannot use a FieldChangeListener as I need to react to the initial button press and to the button release as well.