我制作了一个自定义对话框,如:
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);
}
如何为“查看按钮”和“取消按钮”设置操作? 我搜索过但没找到我要做的事情。 请帮帮我!
答案 0 :(得分:1)
使用DialogClosedListener
将CustomDialog
附加到Dialog.setDialogClosedListener()
。当有人单击其中一个按钮时,将调用DialogClosedListener.dialogClosed()
方法,并将按钮索引作为choice
参数传递。
答案 1 :(得分:0)
查看此代码..这可能对您有帮助..
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);
}
}