基本的android计时器?

时间:2012-01-12 11:58:57

标签: android timer

我想在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();
}

1 个答案:

答案 0 :(得分:1)

试试这个:

AlertDialog.Builder lost = new AlertDialog.Builder(ButtonMasherActivity.this);

AlertDialog.Builder需要Context个对象而不是CountdownTimer个对象。