maxsap
maxsap

Reputation: 3001

android how to show a dialog for a specific time

I would like to show an alert dialog that shows a counter(timer of time) and after 10 seconds will automatically disappear.

I have:

builder = new AlertDialog.Builder(this);
    builder.setTitle(title);
    builder.setMessage(msg);
    final EditText input = new EditText(this);
    builder.setView(input);
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            builder.setMessage("ELEOS");
        }
    });
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dismissDialog(id);
        }
    });
    return builder.create();

which simply creates the dialog.

Upvotes: 0

Views: 2432

Answers (1)

Greg Giacovelli
Greg Giacovelli

Reputation: 10184

There is a class android.os.CountDownTimer just for this. Create one and in the onFinish() dismiss your dialog.

Upvotes: 4

Related Questions