将字段添加到BlackBerry PopupScreen

时间:2010-11-08 13:35:19

标签: blackberry java-me

我想将字段和按钮添加到BlackBerry PopupScreen

3 个答案:

答案 0 :(得分:1)

您想要像这样自定义弹出屏幕

public class CustomPopUpScreen extends PopupScreen {
    public CustomPopUpScreen() {
        super(new VerticalFieldManager(CustomPopUpScreen.NO_HORIZONTAL_SCROLL));
        add(new ButtonField());
        add(new ButtonField());
    }
}

此代码可以帮助您

答案 1 :(得分:1)

在这里,我创建了PopupScreen类型的对象,并调用方法givePopup

PopupScreen popup1=givePopup();
PopupScreen givePopup(){
    VerticalFieldManager popvfm =new VerticalFieldManager();
    ButtonField ok=new ButtonField("ok");
    ButtonField cancel=new ButtonField("cancel");
    popvfm.add(ok);
    popvfm.add(cancel);
    PopupScreen popup=new PopupScreen(popvfm);
    return popup;
}

此方法返回一个PopupScreen实例,该实例具有一个垂直字段管理器,并在此管理器上添加两个按钮字段。

答案 2 :(得分:1)

public class FriendPopupScreen extends MainScreen{
    int dialogWidth;
    int dialogHeight;
    LabelField lblTitle;

    HorizontalFieldManager hfmTitle;

    Vector data;

    public FriendPopupScreen() {

        dialogWidth = 300;
        dialogHeight = 150;

        lblTitle = newLabelField("Choose option");

        hfmTitle = new HorizontalFieldManager(USE_ALL_WIDTH){

            protected void sublayout(int maxWidth, int maxHeight) {
                // TODO Auto-generated method stub
                maxWidth= Display.getWidth();
                maxHeight=40;
                super.sublayout(maxWidth, maxHeight);
                setExtent(maxWidth, maxHeight);
            }

            protected void paint(Graphics graphics) {
                // TODO Auto-generated method stub

                graphics.setBackgroundColor(Color.BLACK);
                graphics.clear();
                super.paint(graphics);
            }

        };

        hfmTitle.add(lblTitle);
        lblTitle.setMargin(10,0,0,10);
        add(hfmTitle);
    }
     protected void sublayout( int width, int height ) {
            setExtent( dialogWidth, dialogHeight );
            setPosition( Display.getWidth()/2-(dialogWidth/2), Display.getHeight()/2 - (dialogHeight/2));
            layoutDelegate( dialogWidth, dialogHeight );
        }
}

并称之为:

FriendPopupScreen popup = new FriendPopupScreen();
UiApplication.getUiApplication().pushModalScreen(popup);