Reputation: 850
I would like to have a timer that goes for like 20 seconds and at every 5 sec which could change the boolean from false to true and it could reset in other second. for instance
Timer t = new Timer(20);
from seconds 1 - 4 : boolean false
second 5 : boolean true
Upvotes: 0
Views: 239
Reputation: 6200
new CountDownTimer(20000, 1000) {
public void onTick(long millisUntilFinished) {
long seconds = millisUntilFinished / 1000;
Log.d(TAG, "onTick:: seconds="+seconds);
if ((seconds % 5) == 0) {
Log.d(TAG, "onTick:: 5 seconds lap");
//set your boolean variable to true
}else{
//set your boolean variable to false
}
}
public void onFinish() {}
}.start();
Upvotes: 1
Reputation: 173
Try this:
new CountDownTimer(20000, 5000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
//your code here for setting the boolean
}
}.start();
Upvotes: 1