我想在5秒后弹出对话框。有人可以向我解释我做错了什么吗?我在计时器的Finish()部分得到一个错误,(我现在只编程了大约三个月,所以请忍受我的愚蠢。
public void run() {
CountDownTimer counter = new CountDownTimer(5000,1000) {
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
}
public void onFinish() {
if (count == value) {
AlertDialog.Builder lost = new AlertDialog.Builder(this); // <-----There is my error its telling me // to go and set up my dialog AlertDialog.Builder(new CountDownTimer(){}) { And I dont understand it
lost.setMessage("You lost! you are ugly!" +
"" +
" new game?");
lost.setCancelable(false);
lost.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
clicks.setText("Clicks ");
count = 1;
generator = new Random();
value = generator.nextInt(100);
imgBtn.setImageResource(R.drawable.push);
}
});
lost.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
generator = new Random();
value = generator.nextInt(100);
ButtonMasherActivity.this.finish();
}
});
lost.create();
lost.show();
}
}
};
counter.start();
}
答案 0 :(得分:1)
试试这个:
AlertDialog.Builder lost = new AlertDialog.Builder(ButtonMasherActivity.this);
AlertDialog.Builder
需要Context
个对象而不是CountdownTimer
个对象。