0

Here is an example of creating the progress dialog:

First situation:

private ProgressDialog progressDialog;

btnCircle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                progressDialog = ProgressDialog.show(MainActivity.this, 
                "Loading", "Please Wait");
                SporednaDretva sd = new SporednaDretva(progressDialog, false);
                sd.start();

            }
        });

Please notice that here I have "progressDialog = ProgressDialog.show(MainActivity.this, "Loading", "Please Wait");"

Second situation:

btnProgress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                progressDialog = new ProgressDialog(MainActivity.this);
                progressDialog.setMessage("Downloading");
                progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                progressDialog.show();
                SporednaDretva sd = new SporednaDretva(progressDialog, true);
                sd.start();

            }
        });

Here I have "progressDialog = new ProgressDialog(MainActivity.this);"

QUESTION: Can anyone explain to me a little bit about these 2 ways of creating a progress dialog? I know that the first dialog is circle dialog and second is horizontal progress dialog, but why in the first example I have "progressDialog = ProgressDialog.show(MainActivity.this, "Loading", "Please Wait")" without new ProgressDialog() and in the second example I have new ProgresDialog()?

Dezo
  • 835
  • 9
  • 16

1 Answers1

0

Interesting . The first on is a static method of ProgressDialog class which extends AlertDialog which extends Dialog. Now the second one is a non static method of Dialog class.The same which inherited by alertdialog.

Hence it seems first one is better to call for programmer ease of use. However the first one's body is below one!

public static ProgressDialog show(Context context, CharSequence title,
            CharSequence message, boolean indeterminate,
            boolean cancelable, OnCancelListener cancelListener) {
        ProgressDialog dialog = new ProgressDialog(context);
        dialog.setTitle(title);
        dialog.setMessage(message);
        dialog.setIndeterminate(indeterminate);
        dialog.setCancelable(cancelable);
        dialog.setOnCancelListener(cancelListener);
        dialog.show();
        return dialog;
    }

which is the second one.

Koustuv Ganguly
  • 897
  • 7
  • 21