【问题标题】:AlertDialog.Builder open another AlertDialog.BuilderAlertDialog.Builder 打开另一个 AlertDialog.Builder
【发布时间】:2012-02-18 17:18:21
【问题描述】:

我正在尝试在另一个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();

【问题讨论】:

  • 定义“不工作”。尝试在另一个 AlertDialog 中打开 AlertDialog 时是否收到任何错误消息?

标签: android dialog android-alertdialog


【解决方案1】:

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

所以,构建第一个AlertDialog 应该是这样的

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

然后

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

第二个。

【讨论】:

  • @FelipeSuman 这些论坛的习惯是在找到答案后接受答案(单击旁边的复选标记)。谢谢,祝你好运!
  • 它帮助我解决了类似的问题,需要另一个支持
猜你喜欢
  • 1970-01-01
  • 2012-07-02
  • 2019-02-10
  • 2011-10-13
  • 1970-01-01
  • 1970-01-01
  • 2013-07-27
  • 2018-05-19
  • 1970-01-01
相关资源
最近更新 更多