0
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class PlantNow extends Activity implements OnClickListener{

Button cd;
TextView tvcd;

public class MyCountDownTimer extends CountDownTimer {

    public MyCountDownTimer(long startTime, long interval) {
            super(startTime, interval);             
        }

    @Override
    public void onFinish() {
        tvcd.setTextSize(30);
       tvcd.setText("BOOOOOOOOM");
    }

    @Override
    public void onTick(long millisUntilFinished) {
         tvcd.setText("" + millisUntilFinished/1000);
    }
}
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    //FullScreen Start
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    //FullScreen End
    setContentView(R.layout.plantnow);
    tvcd=(TextView)findViewById(R.id.tvcd);
    cd=(Button)findViewById(R.id.b11);
    cd.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    switch(arg0.getId()){
    case R.id.b11:
        tvcd.setTextSize(20);
        tvcd.setText("Message Here");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        MyCountDownTimer countDownTimer = new MyCountDownTimer(30000, 1000);
        break;
    }

}

这是当前的代码,我有,我也添加了新的 MyCountdowntimer 类,但它警告我我的帖子主要是代码,哦,天哪,为什么,我对 stackflow 有点陌生,它给了我很多问题 xD

4

1 回答 1

1
public class MyCountDownTimer extends CountDownTimer {
     public MyCountDownTimer(long startTime, long interval) {
        super(startTime, interval);
     }

     @Override
     public void onFinish() {
        text.setText("Time's up!");
     }

     @Override
     public void onTick(long millisUntilFinished) {
          text.setText("" + millisUntilFinished/1000);
     }
}

并开始

MyCountDownTimer countDownTimer = new MyCountDownTimer(30000, 1000);

它将持续 30 秒。onTick 每秒会被调用 29 次。onFinish 是最后一个被调用的

于 2013-06-05T07:19:30.473 回答