2012-02-18 61 views
3

我想在另一个AlertDialog中打开一个AlertDialog,但它不工作,为什么它不工作的任何想法?AlertDialog.Builder打开另一个AlertDialog.Builder

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(); 
+2

定义“不工作”。尝试在另一个AlertDialog中打开AlertDialog时是否收到任何错误消息?谢谢你, – Rob 2012-02-18 17:24:22

回答

6

该问题可能是您用于AlertDialog的环境。尝试在两者中使用MyActivityName.this,用您的Activity的名称替换MyActivityName。

因此,建设的第一个AlertDialog应该是这样的

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

然后

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

的第二个。

+0

真的很有用。现在工作 – 2012-02-19 12:53:09

+0

@FelipeSuman在这些论坛上习惯于接受答案(点击旁边的复选标记)找到答案。谢谢,祝你好运! – koopaking3 2012-03-06 02:21:31

+0

它帮助我解决了类似的问题,需要另一个upvote – 2012-11-26 20:39:02

相关问题