倒数计时器开始直到停止时,如何计算点击次数?

时间:2015-10-20 19:01:37

标签: android android-studio countdowntimer

在我的应用程序中,当我单击文本框时,它开始计算点击次数,并在倒数计时器启动时单击文本框。我希望我的计数器(mCount)在CountDown计时器结束时停止。提前致谢!! 这是我的代码:

TextView tv,t1;

Button reset;

private int mCount = 0;

private final long startTime = 5 * 1000;

private final long interval = 1 * 1000;
private CountDownTimer countDownTimer;
private boolean timerStarted = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play_game);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    tv  = (TextView)findViewById(R.id.tv1);
    tv.setText("5"); // startting from 5.
    reset=(Button)findViewById(R.id.reset);
    final TextView countTextView = (TextView) findViewById(R.id.TextViewCount);
    t1=(TextView)findViewById(R.id.textView2);
    countDownTimer = new MyCountDownTimer(startTime, interval);
    t1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!timerStarted) {
                countDownTimer.start();
                timerStarted = true;
                mCount++;
                countTextView.setText("SCORE: " + mCount);
            }

1 个答案:

答案 0 :(得分:0)

你可以使用countdowmtimer的overriden方法 像这样的东西:

new CountDownTimer(30000,1000){

 public void onTick(long millisUntilFinished) {
     mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
 }

 public void onFinish() {
     mTextField.setText("done!");
 }

}开始();