2017-02-04 3 views
0

タイマーのカウントダウンに伴いダイアログボックスを動的にする方法を教えてください。唯一の時間がそのまま残ります。カウントダウンしない。あなたは残りの時間を設定するには、このようCountDownTimerを使用していないのはなぜここに私は私のダイアログボックスを取得する方法私のコードは...どうすればダイアログボックスをアンドロイドでダイナミックタイマーにすることができますか

 btnTimeLeft.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      AlertDialog.Builder builder = new AlertDialog.Builder(downPaymentActivity.this); 
      builder.setTitle("Time left"); 
      try { 
       SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
       TimeZone tz = TimeZone.getTimeZone("Asia/Manila"); 
       sdf1.setTimeZone(tz); 
       String currentDateandTime = sdf1.format(new Date()); 

       String givenDateString = tvDueDate.getText().toString(); 

       Date date1 = sdf1.parse(currentDateandTime); 
       Date date2 = sdf1.parse(givenDateString); 

       long restDatesinMillis = date2.getTime() - date1.getTime(); 
       String hms = String.format("%02d:%02d:%02d", 
         TimeUnit.MILLISECONDS.toHours(restDatesinMillis), 
         TimeUnit.MILLISECONDS.toMinutes(restDatesinMillis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(restDatesinMillis)), 
         TimeUnit.MILLISECONDS.toSeconds(restDatesinMillis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(restDatesinMillis))); 

       builder.setMessage(hms); 
       builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
        @Override 
        public void onClick(DialogInterface dialogInterface, int i) { 
         dialogInterface.cancel(); 
        } 
       }); 

       builder.show(); 
      } catch (ParseException e) { 
       e.printStackTrace(); 
      } 
     } 
    }); 
} 

答えて

0

です。

new CountDownTimer(30000, 1000) { 

    public void onTick(long millisUntilFinished) { 
     mTextField.setText("seconds remaining: " + millisUntilFinished/1000); 
    } 

    public void onFinish() { 
     mTextField.setText("done!"); 
    } 
    }.start(); 
+0

これをダイアログに入れることはできますか? –

+0

ダイアログの中にTextViewを入れます。tv = new TextView(this); tv.settext(millisUntilFinished); – Simo

+0

勤務していません。 –

関連する問題