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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
swiebertje
Posts: 64
Registered: ‎05-09-2009
Accepted Solution

ButtonField focus problem when handling event

Hi all,

 

I've this button which launches a background thread to do some time consuming stuff. When i press the button and launch the thread the focus is lost. Somehow the button focus is restored after the background thread is finished.

 

Here's a code snippet:

 

 

ButtonField button = new ButtonField("start");
button.setChangeListener(new FieldChangeListener() {
	public void fieldChanged(Field field, int context) {
		startProcess();
	}
});


private void startProcess() {
	new Thread(new Runnable() {
		public void run() {
			// do stuff
		}
	}).start();
}

 

Why does the button looses it's focus when a background thread is running?

 

Thanks!

 

Please use plain text.
Developer
jMarc
Posts: 94
Registered: ‎10-01-2009

Re: ButtonField focus problem when handling event

I haven't tried building it, but your code looks reasonable.  Are you sure the button loses focus?  If you put another button on the screen, can you move between them while the Thread is running?  If you click the same button several times do you get multiple Threads?

Please use plain text.
Developer
ankit2grover
Posts: 159
Registered: ‎08-19-2008

Re: ButtonField focus problem when handling event

Try to instantiate your button with....... new ButtonField("start",ButtonField.CONSUME_CLICK);.......

Please use plain text.
Developer
swiebertje
Posts: 64
Registered: ‎05-09-2009

Re: ButtonField focus problem when handling event

Thanks this works.

Please use plain text.