我该如何开始,通过一个按钮来停止我的countdowntimer?我的、我该、按钮、countdowntimer

由网友(娇情你大爷)分享简介:这是我迄今为止..该程序打开时,它才刚刚起步:This is what I have so far.. it just starts when the application is opened:package com.android.countdown;import android.app.Activity;i...

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

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();
阅读全文

相关推荐

最新文章