How do I set a timer on all of the checkboxes at the same time if I were to uncheck them all at once? If I uncheck "checkbox1" and set up a timer for that checkbox, wouldn't unchecking "checkbox2" override that timer?
- I have 3 checkboxes and 1 textview,
- All checkboxes in the state of checked.
- I want to create a timer when any of them is unchecked.
- I wish to have a independent timer for each checkbox
For example, when "checkbox1" is unchecked, I wish to create a timer that lasts for 5 minutes and when it only has 1 minute left, I want it to change the textview's text to "you have 1 minute left" as a reminder that the timer is ending soon.
public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if (!buttonView.isChecked()) {
new CountDownTimer(300000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
if (millisUntilFinished < 60000) {
map.get(buttonView).setText("1 min left!");
} else if (millisUntilFinished < 30000) {
map.get(buttonView).setText("30 sec left!");
} else {
map.get(buttonView).setText(millisUntilFinished/60000 + ":" + (millisUntilFinished%60000)/1000);
}
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
map.get(buttonView).setText("Spawned!");
}
}.start();
} else if (buttonView.isChecked()) {
// cancel the timer basically
}
}
Unlike what i originally wanted to do, i've created a textview for each checkbox, so it wouldn't be confusing to the user. I've created a map which contains (Checkbox, TextView). How do i cancel the timer when the checkbox is unchecked? do i make an arraylist? if so, where would i add the timer into the arraylist?