2012-05-06 159 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

如果您可以編輯答案以包含一些信息豐富的描述或指向應用程序和活動環境之間的區別的指示器,它會對其他人有幫助嗎? –