03-09-2010 10:17 AM
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!
Solved! Go to Solution.
03-09-2010 03:55 PM
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?
03-09-2010 04:11 PM
Try to instantiate your button with....... new ButtonField("start",ButtonField.CONSUME_CLICK);...
03-10-2010 04:01 AM
Thanks this works.