我想从1到15例如从15开始直到它达到1并重复这个过程......请你帮我完成一下吗?我尝试了一切。而不是如果,我尝试了,而由于某种原因,它给了随机数字。此方法仅减去14.它不会完全倒计时。循环中的countup和倒计时。 android
int counter = 0;
int total = 15;
number = (TextView) this.findViewById(R.id.number);
final Timer c=new Timer();
c.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (counter < total && timerHasStarted) {
runOnUiThread(new Runnable()
{
@Override
public void run()
{
number.setText("" +counter);
counter++;
}
});
}
if (counter <= total && timerHasStarted) {
runOnUiThread(new Runnable()
{
@Override
public void run()
{
number.setText("" +counter);
counter++;
}
});
if (counter == total && timerHasStarted) {
countingDown = true;
if(countingDown){
counter--;
}
else{
counter++;
}
//setting the text here
if(counter%15==0){ //only 0 when counter equals 0 or 15
countingDown=!countingDown; // starting the other direction at next time
}
}
}}}, 1000, 300);
timerHasStarted = true;