开发者

BlackBerry BrowserField IllegalStateException

I'm trying to implement simple user interaction with field2.BrowserField: when button is clicked BrowserField loads another page, but I'm getting IllegalStateException.

here's my code:

public class BrowserScreen extends MainScreen {
  private BrowserField browser;

  public BrowserScreen() {
      super();
      setTitle("Browser State example");

      ButtonField btn1 = new ButtonField("test1");
      btn1.setChangeListener(new FieldChangeListener() {

        public void fieldChanged(Field field, int context) {
            test1();                
        }
      });
      add(btn1);
      ButtonField btn2 = new ButtonField("test2");
      btn2.setChangeListener(new FieldChangeListener() {

        public void fieldChanged(Field field, int context) {
            test2();                
        }
      });
      add(btn2);

      browser = new BrowserField();
      add(browser);
      browser.requestContent("http://stackoverflow.com/" + ";deviceside=true;");
  }

  private void test1() {
      UiApplication.getUiApplication().invokeLater(new Runnable() {         
        public void run() {             
            browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
        }
    });

  }

  private void test2() {
      synchronized (Applica开发者_如何学Pythontion.getEventLock())
        {
         browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
        }
  }

}


Try this one:

public class BrowserScreen extends MainScreen {
  private BrowserField browser;

  public BrowserScreen() {
      super();
      setTitle("Browser State example");

  ButtonField btn1 = new ButtonField("test1");
  btn1.setChangeListener(new FieldChangeListener() {

    public void fieldChanged(Field field, int context) {
        //test1();
        test1("http://www.blackberry.com/developers");
    }
  });
  add(btn1);
  ButtonField btn2 = new ButtonField("test2");
  btn2.setChangeListener(new FieldChangeListener() {

    public void fieldChanged(Field field, int context) {
        //test2();
        test1("http://www.blackberry.com/developers");
    }
  });
  add(btn2);

  browser = new BrowserField();
  add(browser);

  //browser.requestContent("http://stackoverflow.com/" + ";deviceside=true;");
  test1("http://stackoverflow.com/");
}

  private void test1(final String url) {
      UiApplication.getUiApplication().invokeLater(new Runnable() {         
        public void run() {     
            //browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
            browser.requestContent(url + ";deviceside=true");
        }
    });

  }

//  private void test2() {
//      synchronized (Application.getEventLock())
//        {
//         browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
//        }
//  }
}


Wow, adding browser.setFocus(); do the trick

public class BrowserScreen extends MainScreen {
  private BrowserField browser;

  public BrowserScreen() {
      super();
      setTitle("Browser State example");

      ButtonField btn1 = new ButtonField("test1", ButtonField.CONSUME_CLICK);
      btn1.setChangeListener(new FieldChangeListener() {

        public void fieldChanged(Field field, int context) {
            test1();                
        }
      });
      add(btn1);

      browser = new BrowserField();
      add(browser);
      browser.requestContent("http://stackoverflow.com/" + ";deviceside=true;");
  }

  private void test1() {
      UiApplication.getUiApplication().invokeLater(new Runnable() {         
        public void run() {      
            browser.setFocus();
            browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
        }
    });

  }

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜