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 < / p>
答案 0 :(得分: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是最后一个被称为