需要延迟循环[Android]


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类,以及,但它给我警告,我的帖子主要是代码,哦,天哪,为什么,我有点新的堆栈流,它给了我很多问题xD

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是最后被调用的

最新更新