简体   繁体   中英

How to show Alert dialog after processbar dialog dismiss?

i want to show alert dialog after processbar dialog dismis (cick on listview to show processbar) : this is my code show processbar dialog:

ProgressDialog barProgressDialog;
Handler updateBarHandler;

public void launchBarDialog(View view)
{
    barProgressDialog = new ProgressDialog(MainActivity.this);

    barProgressDialog.setTitle("Processing,please wait ...");
    barProgressDialog.setMessage("Cracking password in progress ...");
    barProgressDialog.setProgressStyle(barProgressDialog.STYLE_HORIZONTAL);
    barProgressDialog.setProgress(0);
    barProgressDialog.setMax(10);
    barProgressDialog.show();

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {

                // Here you should write your time consuming task...
                while (barProgressDialog.getProgress() <= barProgressDialog.getMax()) {

                    Thread.sleep(1000);

                    updateBarHandler.post(new Runnable() {

                        public void run() {

                            barProgressDialog.incrementProgressBy(2);
                          }
                      });
                    if (barProgressDialog.getProgress() == barProgressDialog.getMax()) {
                        barProgressDialog.dismiss();


                    }
                }
            } catch (Exception e) {
            }
        }
    }).start();




}

Please post sample code. Thank you very much!!!

You need to implement the interface DialogInterface.OnDismissListener on method 上实现DialogInterface.OnDismissListener接口 It will help you to do what you need. The code below will help you to do what you need.

ProgressDialog barProgressDialog;
Handler updateBarHandler;

public void launchBarDialog(View view) {
    updateBarHandler = new Handler();
    barProgressDialog = new ProgressDialog(MainActivity.this);
    barProgressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            //Put your AlertDialog Here ....
            AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
            alert.setMessage("This Alert Dialog will be show after the ProgressDialog dismissed");
            alert.show();

        }
    });
    barProgressDialog.setTitle("Processing,please wait ...");
    barProgressDialog.setMessage("Cracking password in progress ...");
    barProgressDialog.setProgressStyle(barProgressDialog.STYLE_HORIZONTAL);
    barProgressDialog.setProgress(0);
    barProgressDialog.setMax(10);
    barProgressDialog.show();

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                // Here you should write your time consuming task...
                while (barProgressDialog.getProgress() <= barProgressDialog
                        .getMax()) {

                    Thread.sleep(1000);
                    updateBarHandler.post(new Runnable() {
                        public void run() {
                            barProgressDialog.incrementProgressBy(2);

                            if (barProgressDialog.getProgress() == barProgressDialog
                                    .getMax()) {
                                barProgressDialog.dismiss();
                            }
                        }
                    });
                }
            } catch (Exception e) {
                Log.e("thiago", "error when trying to run the Thread==>"+e.getMessage());
            }
        }
    }).start();
}

I hope that code help you to solve your problem. :)

You just need to place

updateBarHandler = new Handler();

Here is a complete example of what you need:

http://turboprogramacion.blogspot.cl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM