如何在黑莓运行时添加字段?

时间:2013-02-12 05:19:26

标签: blackberry

我是黑莓新手并且被困在一个地方。我有一个自定义下拉菜单,我想如果我从菜单中选择第二个选项应该添加一个字段,如果我从菜单中选择第一个选项应该删除相同的字段。这是我的自定义下拉列表。

       public FWCustomChoiceField(final Object choice[]) {
    edit_field = GlobalUtils.getImage(Display.getWidth() + "x"+ Display.getHeight() + "bb_dropdown1.png");

    this.choice = new Object[choice.length];
    this.choice = choice;
    text = choice[0].toString();
    choiceField = new ListField() {
        protected boolean navigationClick(int status, int time) {
            //buttonIndexFunctionality(getSelectedIndex());

            Field focus = UiApplication.getUiApplication().getActiveScreen().getLeafFieldWithFocus();
            if (focus instanceof ListField) {
                ChoicePopupScreen popup = new ChoicePopupScreen(20, Display.getHeight()/ 2 - (choice.length * 20), choice);
                popup.setChoice(choice);
                UiApplication.getUiApplication().pushScreen(popup);
            }
            return super.navigationClick(status, time);
        }
    };



    choiceField.setSize(1);
    choiceField.setCallback(new TestListCallback());
    add(choiceField);
    invalidate();
}
    public int getListFieldIndex()
{

    return choiceField.getSelectedIndex();
}

public void setSelIndex(int index) {
    this.index = index;
    this.text = choice[index].toString();
    choiceField.invalidate();
}

public String getValue() {
    String value = choice[index1].toString();
    return value;

}

public int getSelectedIndex() {
    return index;
}

我搜索并发现我需要在运行时重建屏幕,但无法弄清楚如何操作。

1 个答案:

答案 0 :(得分:0)

首先创建一个Field Manager并将其添加到您的屏幕上。

 VerticalFieldManager title1;
 title1=new VerticalFieldManager(FIELD_HCENTER)
           {

           };
 title1.add(new NullField());
 add(title1);

现在,当您在下拉列表中选择第二项时,请执行以下操作 -

title1.deleteAll();
title1.add(add your field);//here add your field to title1.
title1.invalidate();

当您点击下拉列表中的第一项时, -

title1.deleteAll();
title1.invalidate();