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: 64
Registered: ‎05-09-2009
My Device: Not Specified
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!

 

Developer
Posts: 94
Registered: ‎10-01-2009
My Device: Not Specified

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?

Developer
Posts: 159
Registered: ‎08-19-2008
My Device: Not Specified

Re: ButtonField focus problem when handling event

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

Highlighted
Developer
Posts: 64
Registered: ‎05-09-2009
My Device: Not Specified

Re: ButtonField focus problem when handling event

Thanks this works.