AlertDialog.Builder 打开另一个 AlertDialog.Builder

发布于 2025-01-06 21:27:58 字数 967 浏览 2 评论 0原文

我正在尝试在另一个 AlertDialog 中打开一个 AlertDialog,但它不起作用,您知道为什么它不起作用吗?

String items[] = {"Details","Edit","Delete"}
AlertDialog.Builder alert = new AlertDialog.Builder(getAplicationContext());
alert.setTitle("Options");
alert.setItems(items, new OnClickListener() {

    public void onClick(DialogInterface dialog, int item) {
        switch(item){
            case 0:
                AlertDialog.Builder alert2 = new AlertDialog.Builder(getAplicationContext());
                alert2.setTitle("Details");
                alert2.setMessage(getDetails());
                alert2.setNeutralButton("Close", null);
                alert2.show();
            return;

            case 1:
                //not important for the question
            return;

            case 2:
                //not important for the question
            return;
        }
    }
});

alert.setNegativeButton("Cancel", null);
alert.show();

I'm trying to open a AlertDialog in another AlertDialog, but it's not working, any ideas why it's not working?

String items[] = {"Details","Edit","Delete"}
AlertDialog.Builder alert = new AlertDialog.Builder(getAplicationContext());
alert.setTitle("Options");
alert.setItems(items, new OnClickListener() {

    public void onClick(DialogInterface dialog, int item) {
        switch(item){
            case 0:
                AlertDialog.Builder alert2 = new AlertDialog.Builder(getAplicationContext());
                alert2.setTitle("Details");
                alert2.setMessage(getDetails());
                alert2.setNeutralButton("Close", null);
                alert2.show();
            return;

            case 1:
                //not important for the question
            return;

            case 2:
                //not important for the question
            return;
        }
    }
});

alert.setNegativeButton("Cancel", null);
alert.show();

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

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

发布评论

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

评论(1

怪我鬧 2025-01-13 21:27:58

问题可能是您用于 AlertDialog 的上下文。尝试在两者中使用 MyActivityName.this,将 MyActivityName 替换为您的 Activity 的名称。

因此,构建第一个 AlertDialog 应该如下所示

AlertDialog.Builderalert = new AlertDialog.Builder(MyActivityName.this);

然后

AlertDialog.Builderalert2 = new AlertDialog.Builder(MyActivityName.this);

用于第二个。

The problem is probably the context you are using for the AlertDialog's. Try using MyActivityName.this in both, replacing MyActivityName with whatever the name of your Activity is.

So, building the first AlertDialog should look like this

AlertDialog.Builder alert = new AlertDialog.Builder(MyActivityName.this);

and then

AlertDialog.Builder alert2 = new AlertDialog.Builder(MyActivityName.this);

for the second one.

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