我想CountDownTimer
在一个countdownTimer
完成它的执行时调用它。我尝试从另一个方法调用一个,countdowntimer
但是当我运行这段代码时它给了我。countdown timer
onFinish()
nullpointer exception
public void First_Timer(){
Timer_Off =false;
dialog = new Dialog(context,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialog.setCancelable(false);
dialog.setContentView(R.layout.backwash_timer_dialog);
final ToggleButton togglebtn_BW_timer = (ToggleButton)dialog.findViewById(R.id.togglebtn_BW_timer);
final ProgressBar bar = (ProgressBar)dialog.findViewById(R.id.progressBar1);
textView1 = (TextView)dialog.findViewById(R.id.textView1);
btn_BW_timer_stop = (Button)dialog.findViewById(R.id.btn_BW_timer_stop);
/** CountDownTimer starts with 2 minutes and every onTick is 1 second */
cdt = new CountDownTimer(twoMin, 1000) {
public void onTick(long millisUntilFinished) {
bar.setProgress((int) ((millisUntilFinished / 1000) ));
messageHandler.sendMessage(Message.obtain(messageHandler,(int) ((millisUntilFinished / 1000) ) ));
}
public void onFinish(){
textView1.setText("Time Up! ");
cdt.cancel();
Timer_Off =true;
dialog.dismiss();
// Call Second Timer Here
Second_Timer();
}
}.start();
btn_BW_timer_stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
cdt.cancel();
bar.setProgress(0);
textView1.setText("0");
Timer_Off=true;
dialog.dismiss();
//onBackwashStopped();
}
});
dialog.show();
}
另一个计时器的代码是,
public void Second_Timer(){
Timer_Rinse_Off =false;
dialog_Rinse = new Dialog(context,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialog_Rinse.setCancelable(false);
dialog_Rinse.setContentView(R.layout.rinse_timer_dialog);
final ProgressBar bar = (ProgressBar)dialog.findViewById(R.id.progressbar_Rinse);
txtRinse_TimerVal = (TextView)dialog.findViewById(R.id.txtRinse_TimerVal);
btn_Rinse_timer_stop = (Button)dialog.findViewById(R.id.btn_Rinse_timer_stop);
/** CountDownTimer starts with 2 minutes and every onTick is 1 second */
cdt_Rinse = new CountDownTimer(twoMin, 1000) {
public void onTick(long millisUntilFinished) {
bar.setProgress((int) ((millisUntilFinished / 1000) ));
messageHandler.sendMessage(Message.obtain(messageHandler,(int) ((millisUntilFinished / 1000) ) ));
}
public void onFinish(){
txtRinse_TimerVal.setText("Time Up! ");
Timer_Rinse_Off =true;
dialog_Rinse.dismiss();
}
}.start();
btn_Rinse_timer_stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
cdt_Rinse.cancel();
bar.setProgress(0);
txtRinse_TimerVal.setText("0");
Timer_Rinse_Off=true;
dialog_Rinse.dismiss();
//onBackwashStopped();
}
});
dialog_Rinse.show();
}