如何在创建FieldChange侦听器后对齐屏幕中心的按钮

时间:2012-02-19 11:42:10

标签: blackberry

我已编写代码将fieldchange侦听器附加到按钮。问题是我希望此按钮居中。我知道按钮居中的代码。问题是获取代码以使按钮居中并包括一个fieldchange侦听器。以下是一些代码段:

    FieldChangeListener listener = new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                ButtonField register = (ButtonField) field;
                UiApplication.getUiApplication().pushScreen(new Register());

}
        }; 

       ButtonField register = new ButtonField("Register",ButtonField.CONSUME_CLICK);  
       register.setChangeListener(listener);
       add(register);

如何将此按钮居中?

1 个答案:

答案 0 :(得分:1)

我把两个和两个放在一起并想出了这个:

     FieldChangeListener listener = new FieldChangeListener() {
                  public void fieldChanged(Field field, int context) {
            ButtonField register = (ButtonField) field;
            UiApplication.getUiApplication().pushScreen(new Register());

    }
    };
          ButtonField menu = new ButtonField("Menu", Field.FIELD_HCENTER); 
      add(menu);
     add(new LabelField("New User?",Field.FIELD_HCENTER));
    ButtonField register = new ButtonField("Register",ButtonField.CONSUME_CLICK|Field.FIELD_HCENTER);  
  register.setChangeListener(listener);
  add(register);

这段代码:

 ButtonField.CONSUME_CLICK|Field.FIELD_HCENTER  

诀窍是什么