开发者

android how to show a dialog for a specific time

开发者 https://www.devze.com 2023-01-20 16:16 出处:网络
I would like to show an alert dialog that shows a counter(timer of time) and after 10 seconds will automatically disappear.

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() {
        @Ove开发者_如何学Pythonrride
        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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消