我創建了一個帶有計時器的遊戲,我試圖讓計時器結束時玩家會看到提醒彈出窗口或任何類型的彈出說「級別完成」,你的點是xxx和下一級的按鈕。我試了一些,但時間過去了,但沒有彈出。 有什麼想法?Android - 計時器功能和alertDialog
時間等級:正常工作。
公共類時間{
private String time;
private boolean isDone;
public Time() {
super();
isDone=false;
}
CountDownTimer count = new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
int seconds = (int) (millisUntilFinished/1000);
int minutes = seconds/60;
seconds = seconds % 60;
String tempSec=Integer.toString(seconds);
if (tempSec.length()==1){
tempSec="0"+tempSec;
}
time="Time Left: " + minutes + ":"+tempSec;
}
public void onFinish() {
setDone(true);
}
}.start();
這是Activity類:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
requestWindowFeature(Window.FEATURE_NO_TITLE);
club=new Club();
clubView = new ClubView(this, club);
mole=new Mole();
stageView=new StageView(this);
moleView=new MoleView(this,mole);
pointsView=new PointsView(this);
time=new Time();
timerView=new TimerView(this, time);
allViews=new AllViews(this);
allViews.setViews(stageView, moleView, pointsView, timerView,clubView);
setContentView(allViews);
allViews.setOnTouchListener((View.OnTouchListener)this);
if (timerView.getTime().isDone()){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Level Complete");
builder.setMessage("your score is"+pointsView.getPoint());
AlertDialog dialog = builder.create();
dialog.show();
}
}
謝謝,優秀的解決方案,任何建議添加按鈕的警報? – cfircoo
看看這裏,http://developer.android.com/guide/topics/ui/dialogs.html setPositiveButton和Negative可能是一個解決方案。 –