Zookey
Zookey

Reputation: 2707

AlertDialog Android HELP

I have one countdown timer, and I want onFinish to pop up yes/no message box, and do something with it, but I get this error: The constructor AlertDialog.Builder(new CountDownTimer(){}) is undefined.

CountDownTimer start1 = null;
start1 = new CountDownTimer(60000, 1000) {

  public void onTick(long millisUntilFinished) {
    tvPreostaloVrijeme.setText(Integer
                               .toString((int) (millisUntilFinished / 1000)));
  }

  public void onFinish() {
    broj1.setText("");
    broj2.setText("");
    op.setText("");
    posalji.setEnabled(false);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
    .setNegativeButton("No", dialogClickListener).show();

  }
} .start();

DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
  @Override
  public void onClick(DialogInterface dialog, int which) {
    switch (which) {
    case DialogInterface.BUTTON_POSITIVE:
      //Yes button clicked
      break;

    case DialogInterface.BUTTON_NEGATIVE:
      //No button clicked
      break;
    }
  }
};

Upvotes: 0

Views: 307

Answers (1)

nicky
nicky

Reputation: 3898

AlertDialog.Builder builder = new AlertDialog.Builder(this);

remove this with getApplicationContext()

AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());

Upvotes: 1

Related Questions