【发布时间】:2015-01-28 18:39:43
【问题描述】:
我的代码包含 2 个倒数计时器,一个在完成后说 GO!然后另一个开始,但是第二个计时器立即开始,然后开始!消息立即消失,如何延迟GO!消息或第二个计时器的出现?这是代码。
public class WorkoutGymEasy1 extends Activity {
CountDownTimer cdt = null;
MediaPlayer mp = null;
TextView c;
Button b;
ImageView image;
TextView pushuptext;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.workout_gym_easy1);
final TextView c = (TextView) findViewById(R.id.timer_gym_easy1);
c.setAlpha(0f);
final Button b = (Button) findViewById(R.id.button1);
b.setAlpha(1f);
final ImageView image = (ImageView) findViewById(R.id.imagePushUp);
b.setAlpha(1f);
final TextView pushuptext = (TextView) findViewById(R.id.textPushUp);
b.setAlpha(1f);
RelativeLayout rl5 = (RelativeLayout) findViewById(R.id.rl5);
rl5.setBackgroundColor(Color.BLACK);
mp = MediaPlayer.create(WorkoutGymEasy1.this, R.raw.countdown);
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
b.setOnClickListener(new OnClickListener() {
public void onClick (View v) {
b.setAlpha(0f);
c.setAlpha(1f);
mp.start();
new CountDownTimer(6000, 1000) { //20 seconds count down with 1s interval (1000 ms) //access TextView element on the screen to set the timer value
public void onTick(long millisUntilFinished) { // Code in this method is executed every 1000ms (1s)
c.setText("" + (millisUntilFinished / 1000) + ""); //update the timer
//if (millisUntilFinished == 0) {
//c.setText("GO!");
//}
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
c.setText("GO!");
// Intent myIntent = new Intent(getApplicationContext(), WorkoutGymEasy2.class);
// startActivity(myIntent);
new CountDownTimer(31000, 1000) { //30 seconds count down with 1s interval (1000 ms) //access TextView element on the screen to set the timer value
public void onTick(long millisUntilFinished) { // Code in this method is executed every 1000ms (1s)
c.setText("" + (millisUntilFinished / 1000) + ""); //update the timer
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
Intent myIntent = new Intent(getApplicationContext(), WorkoutGymEasy2.class);
startActivity(myIntent);
finish(); // call finish() method to destroy this activity and return to instructions screen
}
}.start();
}
}.start();
}
});
}
protected void OnPause() {
super.onPause();
mp.release();
finish();
}
}
【问题讨论】:
标签: android performance android-activity timer countdowntimer