I would be very grateful if someone could explain how to create a simple timer in a game which starts off at 30 seconds and then goes back until 0. At 0 I would then stop the game and invoke a method which would allow the next player to take a turn.
Any advice would be appreciated. Thanks
Edit:
import android.os.CountDownTimer;
import android.widget.TextView;
public class MyCount extends CountDownTimer {
static TextView timeDisplay;
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
public void onFinish() {
timeDisplay.setText("Done!");
}
public void onTick(long millisUntilFinished) {
timeDisplay.setText("Left: " + millisUntilFinished / 1000);
}
}
In a seperate class I have created a method:
public void setTimer() {
timeDisplay = new TextView(this);
this.setContentView(timeDisplay);
MyCount counter = new MyCount(3开发者_如何学Python0000, 1000);
counter.start();
}
Within an onClick method I have called the method above:
public void onClick(View v) {
setTimer();
}
I'd appreciate any advice on this.
精彩评论