Kuls
Kuls

Reputation: 2067

Create global ProgressDialog

I have created common function for displaying custom progressbar in another class. When i call this function Dialog box will be shown but when i want to dismiss that Dialog box than it could not be dismissed. Here is the code

public void showPopupProgressSpinner(Boolean isShowing) {

        Dialog progressDialog;
        ProgressBar progressBar;

        progressDialog = new Dialog(context);
        progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        progressDialog.setContentView(R.layout.popup_progressbar);
        progressDialog.setCancelable(false);
        progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        progressBar = (ProgressBar) progressDialog.findViewById(R.id.progressBar1);
        progressBar.getIndeterminateDrawable().setColorFilter(Color.parseColor("#ff6700"),
                android.graphics.PorterDuff.Mode.MULTIPLY);

        if (isShowing == true) {
            progressDialog.show();
        } else if (isShowing == false) {

            progressDialog.dismiss();

        }
    }

This is how i call this function

To show dialog box

utils.showPopupProgressSpinner(true);

To Hide dialog box

utils.showPopupProgressSpinner(false);

Upvotes: 1

Views: 1733

Answers (1)

Andy Developer
Andy Developer

Reputation: 3101

Try this it works for me.

private Dialog progressDialog = null;
private ProgressBar progressBar;

public void showPopupProgressSpinner(Boolean isShowing) {
    if (isShowing == true) {
        progressDialog = new Dialog(AndroidVideoCaptureExample.this);
        progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        progressDialog.setContentView(R.layout.popup_progressbar);
        progressDialog.setCancelable(false);
        progressDialog.getWindow().setBackgroundDrawable(
                new ColorDrawable(Color.TRANSPARENT));

        progressBar = (ProgressBar) progressDialog
                .findViewById(R.id.progressBar1);
        progressBar.getIndeterminateDrawable().setColorFilter(
                Color.parseColor("#ff6700"),
                android.graphics.PorterDuff.Mode.MULTIPLY);
        progressDialog.show();
    } else if (isShowing == false) {
        progressDialog.dismiss();
    }
}

Thanks.

Upvotes: 3

Related Questions