如何在延迟n秒后动态显示进度对话框按钮

如何在延迟n秒后动态显示进度对话框按钮

本文介绍了如何在延迟n秒后动态显示进度对话框按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在显示ProgressDialog的n秒(固定)延迟后如何显示ProgressDialog按钮?

How to show the ProgressDialog button after n seconds (fixed) delay that the ProgressDialog is shown?

更清楚地说,ProgressDialog正常启动。我如何在n秒后显示按钮?

To be more clear, the ProgressDialog starts normally. How can I show a button within it after n seconds?

LF

编辑 >

使用Segi和android_beginner的答案(非常感谢您),我发布了我的问题的解决方案:

Using the answers of Segi and android_beginner (thank you very much) I'm posting the solution of my problem:

        pDialog = new ProgressDialog(mContext);
        pDialog.setTitle(Reso.getString(mContext, R.string.waiting));
        pDialog.setMessage(Reso.getString(mContext, R.string.waiting));
        pDialog.setIndeterminate(true);
        pDialog.setCancelable(false);
        pDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                Reso.getString(mContext, R.string.annulla),
                new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // Stuff
            }
        });
        pDialog.show();
        pDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.INVISIBLE);

        int progressDialogCancelButtonDelay = 2500;

        new CountDownTimer(progressDialogCancelButtonDelay, progressDialogCancelButtonDelay + 1) {

            @Override public void onTick(long millisUntilFinished) { }

            @Override public void onFinish() {
                pDialog.getButton(ProgressDialog.BUTTON_NEGATIVE).setVisibility(View.VISIBLE);
            }
        }.start();


推荐答案

尝试以下代码:

 ProgressDialog loadingDialog = ProgressDialog.show(activity.this, "", "Loading...",
                true, false);

        new Thread(new Runnable() {

            @Override
            public void run() {
                try {

                    Thread.sleep(2500);
                    runOnUiThread(new Runnable() {
                        public void run() {



                                loadingDialog.dismiss();

                               loadingDialog.setButton(ProgressDialog.BUTTON_NEUTRAL,
                                                 "Close",
                               new DialogInterface.OnClickListener()                 {
                              @Override
                               public void onClick(DialogInterface dialog, int which) {
                            //button click stuff here
                          }
                     });

                    loadingDialog.show();
                   loadingDialog.getButton(ProgressDialog.BUTTON_NEUTRAL).setVisibility(View.INVISIBLE);

                            }
                        }
                    });
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }).start();

这篇关于如何在延迟n秒后动态显示进度对话框按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 04:44