2012-05-06 254 views
0

是否有任何方法可以创建对话框,单击对话框中的按钮进入另一个对话框,然后单击新对话框中的另一个按钮,将会转到上一个对话框?Android中的对话框警报

Dialog - > Dialog2 -> Dialog 

这是我的代码:

private void showIBW() { 

    final String[] frame = { "Small", "medium", "large" }; 

    AlertDialog.Builder framechoice = new AlertDialog.Builder(this); 
    framechoice.setTitle("please choose your frame size"); 
    framechoice.setNeutralButton("what's this?", 
      new DialogInterface.OnClickListener() { 

       public void onClick(DialogInterface dialog, int which) { 

        AlertDialog.Builder help = new AlertDialog.Builder(getApplicationContext()); 
        help.setTitle("Frame explanation"); 
        help.setMessage("cheikh is not helpful"); 
        help.setNeutralButton("okay thanks", new DialogInterface.OnClickListener() { 

         public void onClick(DialogInterface dialog, int which) { 

          ////// Here i want this button to get me back to the "Framechoice" dialog/// 


         } 
        }); 
        help.create(); 
        help.show(); 
       } 

      }); 
    framechoice.setItems(frame, new DialogInterface.OnClickListener() { 

     public void onClick(DialogInterface dialog, int which) { 

      SharedPreferences customSharedPreference = getSharedPreferences(
        "myCustomSharedPrefs", Activity.MODE_PRIVATE); 

      Toast.makeText(getApplicationContext(), frame[which], 
        Toast.LENGTH_LONG).show(); 

      String Height = customSharedPreference.getString("heightpref", 
        null); 
      float height = Integer.parseInt(Height); 

      float weight1 = ((height/100) * (height/100)) * 20; 
      float weight2 = ((height/100) * (height/100)) * 25; 

      AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(
        CalculationsActivity.this); 
      dialogBuilder.setTitle("Ideal weight calculator"); 

      dialogBuilder 
        .setMessage("Your ideal weight is between:\n   " 
          + Math.round(weight1) 
          + " Kg to " 
          + Math.round(weight2) + " kg"); 
      dialogBuilder.setPositiveButton("ok", 
        new DialogInterface.OnClickListener() { 

         public void onClick(DialogInterface dialog, 
           int which) { 

          Intent u = new Intent(); 
          u.setClass(CalculationsActivity.this, 
            CalculationsActivity.class); 
          startActivity(u); 
         } 
        }).create(); 
      dialogBuilder.show(); 

     } 

    }).create(); 
    framechoice.show(); 


} 
+2

什么是从尝试这样做,阻止你? –

+0

我试过了,但是每次点击Dialog2中的按钮时,我都会得到一个空指针。你想看到代码? – callback

+0

是的,给我看相关的代码。 –

回答

0

,如果你正在寻找解决

//////在这里,我想这个按钮让我回“Framechoice” 对话框///

替换成

dialog.cancel(); 

看看是否有帮助。

+0

这会关闭对话框,但不会到达前一个。 – callback

+0

为什么你要在同一个AlertDialog中调用'setNeutralButton'和'setItems'?你能告诉我一个Dialog的图像吗?Dilog盒子会如何看待这两种? –

0

您应该将您的活动用作AlertDialog.Builder的上下文,而不是上下文的应用程序的c 。

更多的信息在这里:

Why does AlertDialog.Builder(Context context) only accepts Activity as a parameter?

https://groups.google.com/forum/?fromgroups#!msg/android-beginners/22dlKekP_V0/t8XfhoDlsQsJ

+1

如果您可以编辑答案以包含一些信息丰富的描述或指向应用程序和活动环境之间的区别的指示器,它会对其他人有帮助吗? –