how can i get the value of a counter counting down?
I’ve been trying with sg like this, but it has a problem with the type:
counter = new MyCount(10000,1000);
String secs;
secs=counter.toString();
if (started == false)
{
counter.start();
started = true;
switch (secs) {
case 8000:
tv3.setTextColor(Color.RED);
break;
case 3000:
tv3.setTextColor(Color.BLUE);
break;
}
}
Update:
MyCount is declared as MyCount counter;
I have also this code:
`public class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
tv = (TextView)findViewById(R.id.TextView01);
tv.setText("Time is up!");
}`
I put the switch part here:
@Override
public void onTick(long millisUntilFinished) {
tv.setText("" + millisUntilFinished/1000);
switch (millisUntilFinished) { //here is the problem
case 8000:
tv3.setTextColor(Color.RED);
break;
case 3000:
tv3.setTextColor(Color.BLUE);
break;
}
}
It had a problem with the switch parameter: “Cannot switch on a value of type long. Only convertible int values or enum constants are permitted“
That is way I have changed that line to switch ((int)millisUntilFinished/1000) { and changed to case lines to case 8: and case 3:.
Thank you!
I don’t know what is
MyCount, but I see the error. Variablesecshas typeString, but you are trying compare it with the integers (3000, 8000). You can’t useStringvariables in theswitchblock. You need use there integer variable or, if counter has String type, use something like this code instead of theswitchblock:Upd: If you use subclass of the CountDownTimer, you need to define
onTick()callback in theMyCountclass, like this: