2011-12-21 23 views
0

私のコードでは、どのようにスイッチやif文をvaribleで作るのですか? id変数とDialogInterfaceの両方が同じであるため、idまたは何かを変更してください。私はこれを行うためのコードとして「ビルダー」を使用していますか?ポスタブがスリープ機能をプルアップしたり、アラームをオフにする機能を作成した場合、ポーズボタンはスヌーズボタンになります。AlertDialogから情報を取得

ここ

私のコードは、

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setMessage("Time to get up! How was your nap?") 
      .setCancelable(false) 
      .setPositiveButton("More Sleep!!", 
        new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          vibarate.cancel(); 
          onPause(); 


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

スイッチをオンにしようとしていますか? – Noah

答えて

1

スヌーズボタンはそう実際にそれがスレッドを眠っているのではなく、与えられた時間のために別のアラームを設定するべきで、onClickListenerです。

私は偽のメソッドを挿入しました:setUpNewAlarmForTime(5、TimeUnit.Seconds); 実際には既にアラームを生成しており、スヌーズコールバックはそれを使用する必要があります。

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setMessage("Time to get up! How was your nap?") 
     .setCancelable(false) 
     .setPositiveButton("More Sleep!!", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 
         vib.cancel(); 
         onPause(); 

         vib = setUpNewAlarmForTime(5,TimeUnit.Seconds); 


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

ありがとう!私のコードは今これで、vibは私のviberateのためのものです。あなたのコードと私の趣味はどうやって結構ですか?ありがとうございました 'AlarmManager am =(AlarmManager)getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP、calendar.getTimeInMillis()、StartActivity()); ' – domshyra

+0

ah、ok。私が行ったことではなく、聴取者にあなたが望む時間でinitコマンドを呼び出させるようにしてください:am.set(AlarmManager.RTC_WAKEUP、calendar.getTimeInMillis()、StartActivity()); – Noah

関連する問題