avast / android-styled-dialogs

Backport of Material dialogs with easy-to-use API based on DialogFragment
Apache License 2.0
2.15k stars 450 forks source link

How to custom styled dialog with progress bar? #12

Closed shinkt closed 11 years ago

shinkt commented 11 years ago

Hi, I wonder can this library work with progress bar? Cause this library use builder to create object, so I don't know how to keep progress bar reference to force update progress. I tried using custom dialog with progress bar on create builder method like this one:

   @Override
protected Builder build(Builder builder) {
    LinearLayout layout = new LinearLayout(getActivity());
    final ProgressBar progressBar = new ProgressBar(getActivity());
    layout.addView(progressBar, new  LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));       
    progressBar.setProgress(0);
    progressBar.setMax(100);
    builder.setView(layout);
    return super.build(builder);
}

And show the dialog

    public ProgressDialog show(FragmentActivity activity, String title){
    ProgressDialog dialog = new ProgressDialog();
    Bundle args = new Bundle();
    args.putString(ARG_TITLE, title);
    dialog.setArguments(args);
    dialog.show(activity.getSupportFragmentManager(), TAG);
      return dialog;
     }

The problem is I don't know how to update the progress to this dialog and dismiss it. Is there any way to do this?

davidvavra commented 11 years ago

You can pass the reference to the progressbar in the show method - but that might now work if you rotate the phone. You could communicate between your progressbar and Fragment with some global messages, for example Otto - http://square.github.io/otto/

tomas-vondracek commented 11 years ago

or you can assign a tag to your ProgressDialog and find it later in your fragment with FragmentManager