2012-04-04 13 views
1

私のアンドロイドプロジェクトをやっていますか?はいといいえボタンでダイアログボックスを作成しました。はいをクリックすると、新しいダイアログボックスが表示され、選択するオプションが表示されます。オプション付きのダイアログボックスを作成しました。しかし、私が最初に作成したダイアログボックスでYESをクリックすると、それを表示できませんでした。どうすればいいですか?助けてください。おかげさまで 別のダイアログボックスのボタンをクリックしてダイアログボックスを表示するにはどうすればいいですか?

私が作成したダイアログボックスのコードです。私は、このダイアログでYESボタンをクリックすると、私はこのことができます別のダイアログ

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setMessage("Low Memory\nYou want to send the file to server?") 
       .setCancelable(false) 
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 

        } 
       }) 
       .setNegativeButton("No", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 
         dialog.cancel(); 
         finish(); 
        } 
       }); 
AlertDialog alert = builder.create(); 
alert.show(); 
+0

は、あなたの質問は本当に明確ではない、あまりにも – waqaslam

+0

をあなたのコードを貼り付けます。何が問題ですか ? logcatはいくつかのエラーを表示していますか? – OcuS

答えて

4
AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setMessage("Low Memory\nYou want to send the file to server?") 
      .setCancelable(false) 
      .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 

        AlertDialog.Builder builder2 = new AlertDialog.Builder(CLASSNAME.this); 
        builder2.setTitle("hi!"); 
        //etc 
        builder2.show(); 

       } 
      }) 
      .setNegativeButton("No", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        dialog.cancel(); 
        finish(); 
       } 
      }); 
    AlertDialog alert = builder.create(); 
    alert.show(); 

希望が表示されます。 ;)

+0

ありがとうございます:)それは動作します。 –

+0

あなたは大歓迎です!左側に正しい印を付けてください。 :) – Xarialon

+0

私はこれをボタンのonClick機能の中に入れますか? – Si8

0

は、このコードを試してみてください。

AlertDialog.Builder builder1 = new AlertDialog.Builder(this); 
     builder1.setMessage("Are you absolutely positively sure?") 
       .setCancelable(false) 
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 

        } 
       }) 
       .setNegativeButton("No", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 
         dialog.cancel(); 
         finish(); 
        } 
       }); 
     final AlertDialog alert1 = builder1.create(); 




     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setMessage("Low Memory\nYou want to send the file to server?") 
       .setCancelable(false) 
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 
         alert1.show(); 
        } 
       }) 
       .setNegativeButton("No", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 
         dialog.cancel(); 
         finish(); 
        } 
       }); 
     AlertDialog alert = builder.create(); 
     alert.show(); 
+0

コードはあなたのために機能しましたか? – Akhil

0

チェックアウトこの

AlertDialog alertDialog1,alertDialog2; 

    public void showAlertDialog1(String title,String message,final Context context) 
      { 
      alertDialog1 = new AlertDialog.Builder(context).create(); 
      alertDialog1.setTitle(title); 
      alertDialog1.setMessage(message); 
      alertDialog1.setButton("OK", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 

        errorAlertDialog2("second AlertDialog","second AlertDialog",context) 

       } 
      }); 
      alertDialog1.show(); 
      } 




     public void showAlertDialog2(String title,String message,Context context) 
      { 
      alertDialog2 = new AlertDialog.Builder(context).create(); 
      alertDialog2.setTitle(title); 
      alertDialog2.setMessage(message); 
      alertDialog2.setButton("OK", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 

        alertDialog2.dismiss(); 
       } 
      }); 
      alertDialog2.show(); 
      }