计数器的Android值
|
我如何获得计数器的价值递减计数?
我一直在尝试使用sg这样的方法,但是类型有问题:
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;
}
}
更新:
MyCount被声明为“ 1”
我也有这段代码:
`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!\");
}`
我把开关部分放在这里:
@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;
}
}
开关参数有问题:“无法打开long类型的值。只允许使用可转换的int值或枚举常量”
这样,我将该行更改为switch ((int)millisUntilFinished/1000) {
,并将大小写行更改为case 8:
和case 3:
。
谢谢!
没有找到相关结果
已邀请:
2 个回复
课刊灭似
,但我看到了错误。变量
的类型为
,但是您尝试将其与整数(3000、8000)进行比较。您不能在
块中使用
变量。您需要使用整数变量,或者,如果计数器具有String类型,则使用类似以下代码的内容,而不是
块:
Upd:如果使用CountDownTimer的子类,则需要在
类中定义
回调,如下所示:
芜任亮蜡