Blackberry 如何在此自定义对话框上设置按钮的操作?
我创建了一个自定义对话框,如下所示:Blackberry 如何在此自定义对话框上设置按钮的操作?,blackberry,customdialog,Blackberry,Customdialog,我创建了一个自定义对话框,如下所示: public class CustomDialog extends Dialog { public CustomDialog(String s) { super(s, new String[] {"View","Cancel"}, new int [] {1,2}, 1, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Manager.FOCUSABLE); } 如
public class CustomDialog extends Dialog {
public CustomDialog(String s) {
super(s, new String[] {"View","Cancel"}, new int [] {1,2}, 1, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Manager.FOCUSABLE);
}
如何设置“查看按钮”和“取消按钮”的操作?
我找了又找不到我要做的事。
请帮帮我 查看此代码。。这可能对你有帮助
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.HorizontalFieldManager;
public class CustomAlertDialog extends Dialog {
public CustomAlertDialog() {
super("Your Custom message for Dialoug" , null, null, Dialog.DISCARD, null, Dialog.VERTICAL_SCROLL);
HorizontalFieldManager hfm = new HorizontalFieldManager();
ButtonField view = null;
view = new ButtonField("view") {
protected boolean navigationClick(int status, int time) {
// do what ever you want
return true;
}
protected boolean keyChar(char key, int status, int time) {
// do what ever you want
return true;
}
};
ButtonField cancel = null;
cancel = new ButtonField("Cancel") {
protected boolean navigationClick(int status, int time) {
// do what ever you want
return true;
}
protected boolean keyChar(char key, int status, int time) {
// do what ever you want
return true;
}
};
hfm.add(view);
hfm.add(cancel);
this.add(hfm);
}
}
使用
Dialog.setDialogClosedListener()
将对话框ClosedListener
附加到CustomDialog
上。当有人单击任一按钮时,将调用DialogClosedListener.dialogClosed()
方法,按钮索引将作为选项
参数传递。非常感谢您,此代码非常有用。但我使用action close()作为“取消按钮”,我必须单击两次才能关闭对话框。我在模拟器上工作。你能解释一下原因吗?哦,这是模拟器的问题,我换了simualotor,它工作得很好。:)如果您提供了一个选项的对象数组,那么这是可行的,但是如果您使用的是自定义按钮字段,那么返回的choice
总是-1。