BlackBerry OS (v. 4 - 6) 是否有带有文本输入字段的模式对话框?
我有一个图形应用程序,我想避免在它的画布上绘画,只需在用户的脸上扔一个模态并要求一小段文字。
BlackBerry OS (v. 4 - 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());
试试下面的代码:
保持这些全局:
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());
}