Question

I made an app ,and there is a progress dialog on one of its activities . I want to show an alert dialog , when progress dialog has finished. How can I do it?

please guid me...

thanks.

Était-ce utile?

La solution

I am assuming you already know how to show the progress dialog. The progress dialog has two listeners, onDismiss and onCancel. Check out the difference here : What is the difference between a dialog being dismissed or canceled in Android?

You can choose to put either of the listeners depending on your requirements. Here's a sample code.

progressDialog.setOnDismissListener(new OnDismissListener() {
    @Override
    public void onDismiss(DialogInterface dialog) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            context);

        // set title
        alertDialogBuilder.setTitle("Your Title");

        // set dialog message
        alertDialogBuilder
            .setMessage("Message")
            .setCancelable(false)
            .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                }
              })
            .setNegativeButton("No",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                }
            });

            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();
        }
    });
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top