黑莓模态文本输入

时间:2012-04-30 08:43:27

标签: java api user-interface blackberry dialog

BlackBerry OS(v.4 - 6)是否有模式对话框,其中包含文本输入字段?

我有一个图形应用程序,我想避免在它的画布上绘画,只是在用户的脸上抛出一个模态并要求一小段文字。

2 个答案:

答案 0 :(得分:6)

请尝试以下代码:

Dialog dialog = new Dialog(Dialog.D_OK, "Title", 0, null, 0);
EditField ef = new EditField("Input: ", "");
((DialogFieldManager)dialog.getDelegate()).getCustomManager().add(ef);

// show modal dialog, wait for response
dialog.doModal();

// get the input text
Dialog.alert(ef.getText());


要进行更多自定义,需要扩展net.rim.device.api.ui.component.Dialog。以下代码将执行与上述相同的操作。

class InputDialog extends Dialog {
    private EditField inputField;

    public InputDialog() {
        super(Dialog.D_OK, "Input Dialog", 0, null, 0);
        Manager delegate = getDelegate();
        if (delegate instanceof DialogFieldManager) {
            DialogFieldManager dfm = (DialogFieldManager) delegate;
            Manager manager = dfm.getCustomManager();
            inputField = new EditField("Input: ", "", 50, EditField.EDITABLE);
            if (manager != null) {
                manager.insert(inputField, 0);
            }
        }
    }

    public String getInputText() {
        return (inputField == null) ? "" : inputField.getText();
    }
}


用法:

InputDialog seaerchDialog = new InputDialog();
// show modal dialog, wait for response
seaerchDialog.doModal();        
// get the input text
Dialog.alert(seaerchDialog.getInputText());

答案 1 :(得分:3)

请尝试以下代码:

保持这些全球性:

Dialog dialog;    
BasicEditField bEditField = new BasicEditField();

然后像这样制作自定义对话框:

dialog = new Dialog(Dialog.OK, "Enter Value:", Dialog.OK, null, Dialog.DEFAULT_CLOSE);
dialog.add(bEditField);

从某个按钮或菜单操作中调用dialog.doModal()

int i = dialog.doModal();
if(i == Dialog.OK) {
    Dialog.inform("The Input Text is : " + bEditField.getText());
}