타이머가있는 게임을 만들었습니다. 타이머가 끝나면 플레이어가 경고 팝업이나 "레벨 완성"이라고하는 팝업을 보게됩니다. 점수는 xxx입니다. 다음 단계를위한 버튼. 뭔가를 시도했지만 시간이 지났지 만 팝업이 없습니다. 아이디어가 있으십니까?안드로이드 - 타이머 기능 및 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();
이는 활동 클래스입니다 :
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();
}
}
감사합니다, Excelent 솔루션, 경고에 버튼을 추가하는 것에 대한 조언이 있습니까? – cfircoo
여기를 보시면 http://developer.android.com/guide/topics/ui/dialogs.html setPositiveButton과 Negative가 해결책이 될 수 있습니다. –