我该如何开始,通过一个按钮来停止我的countdowntimer? [英] How can I start and stop my countdowntimer via a button?

查看:231
本文介绍了我该如何开始,通过一个按钮来停止我的countdowntimer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我迄今为止..该程序打开时,它才刚刚起步:

This is what I have so far.. it just starts when the application is opened:

package com.android.countdown;

import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;

public class countdown extends Activity {

    TextView mTextField;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mTextField = (TextView) findViewById(R.id.timer1);

        new CountDownTimer(100000, 1000) {
            public void onTick(long millisUntilFinished) {
                mTextField.setText("Seconds remaining: " + millisUntilFinished / 1000);
            }

            public void onFinish() {
                mTextField.setText("Finished");
            }
        }.start();
    }
}

我知道我需要调用开始()按钮过程内。但是,如果我移动。开始()从那里它是在新CountDownTimer(100000,1000){变一个错误。

I know that I need to call start() inside a button procedure. However, if I move the .start() from where it's at the new CountDownTimer(100000 , 1000) { gets an error.

推荐答案

呃......也许你需要先了解Java和编程工作。然后,您可以尝试做这样的事情:

Well... maybe you need to first understand how Java and programming work. Then, you can try to do something like this:

CountDownTimer aCounter = new CountDownTimer(100000 , 1000) {
    public void onTick(long millisUntilFinished) {
        mTextField.setText("Seconds remaining: " + millisUntilFinished / 1000);
    }

    public void onFinish() {
        mTextField.setText("Finished");
    }
};
aCounter.start();

这篇关于我该如何开始,通过一个按钮来停止我的countdowntimer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆