Button button;
EditText editText;
CountDownTimer timer;
int min = 0;
int sec = 0;
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
timer = new CountDownTimer(61000,1000) {
@Override
public void onTick(long millisUntilFinished) {
if (sec==59){
sec = 0;
min = min+1;
String text = String.format(Locale.getDefault(),"%02d min: %02d sec",min,sec);
editText.setText(text);
}else {
sec = sec+1;
String text = String.format(Locale.getDefault(),"%02d min: %02d sec",min,sec);
editText.setText(text);
}
}
@Override
public void onFinish() {
Toast.makeText(DesignActivity.this, "Timer Stopped...", Toast.LENGTH_SHORT).show();
}
};
timer.start();
}
});
No comments:
Post a Comment