Search code examples
blackberryblackberry-simulator

move the BlackBerry focus from code


I have 3 buttons A, B and C. When I click A, the page reloads and the focus will be on A and when I click B, the page reloads and focus will be on B and so on. How do I implement this?

if(constants.focuz.equals("next")){ 
          next.setFocus(); 
}else if (constants.focuz.equals("prev")){ 
          prev.setFocus(); 
} else{ 
          abtme.setFocus(); 
}

Solution

  • Your code is Ok. You probably call it on a non-UI thread? If yes, then use UiApplication.invokeLater(Runnable action) to reset the focus. So it should be something like this:

    UiApplication.getUiApplication.invokeLater(new Runnable() {
        public void run() {
            if (constants.focuz.equals("next")) {
                next.setFocus();
            } else if (constants.focuz.equals("prev")) {
                prev.setFocus();
            } else {
                abtme.setFocus();
            }
        }
    });