如何在此自定义对话框上设置按钮的操作?

发布于 2024-12-04 20:05:05 字数 351 浏览 3 评论 0原文

我制作了一个自定义对话框,如下所示:

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);

    }

如何为“查看按钮”和“取消按钮”设置操作? 我搜索了但没有找到我必须做的事情。 请帮我 !

I make a custom Dialog like as :

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);

    }

How can I set action for "View button" and " Cancel button " ?
I searched and not found what I have to do .
Please help me !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愁杀 2024-12-11 20:05:05

使用 Dialog.setDialogClosedListener()DialogClosedListener 附加到您的 CustomDialog。当有人单击任一按钮时,将调用 DialogClosedListener.dialogClosed() 方法,并且按钮索引将作为 choice 参数传递。

Attach a DialogClosedListener to your CustomDialog using Dialog.setDialogClosedListener(). When someone clicks either of the buttons, the DialogClosedListener.dialogClosed() method will be called and the button index will be passed as the choice parameter.

清君侧 2024-12-11 20:05:05

查看此代码..这可能对您有帮助..

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);
    }
}

Check out this code.. this might help you..

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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文