问题是:如何在倒计时过程中添加或删除倒计时计时器中的时间?
例如:用户做了好事+5秒,用户做了坏事-5秒。
有人能帮我弄点密码吗?

最佳答案

也许是这样的

abstract class MyTimer {

    public MyTimer(long deadline, long interval)
    {
        mDeadline = deadline;
        mInterval = interval;

        mTimer = new MyCountDownTimer(mDeadline, mInterval);

    }

    public synchronized void start() {

       mTimer.start();

    }

    public abstract void onTick(long time);
    public abstract void onFinish();

    public synchronized void userDidRight()
    {
        mTimer.cancel();
        mTimer = new MyCountDownTimer(mDeadline, mInterval += 5000);
        mTimer.start();
    }

    public synchronized void userDidWrong()
    {
        mTimer.cancel();
        mTimer = new MyCountDownTimer(mDeadline, mInterfval -= 5000);
        mTimer.start();
    }


    private class MyCountDownTimer extends CountDownTimer() {

        private abstract void onFinish() {
            MyTimer.this.onFinish();
        }

        private abstract void onTick(long time) {
            MyTimer.this.onTick(time);
        }
    }

    private MyCountDownTimer mTimer;
}

09-03 22:33