Search code examples
androidprogressdialogandroid-4.0-ice-cream-sandwich

ProgressDialog#setIndeterminate(false) not working


I'm trying to display a determinate progress dialog with a bar, however, I can't get it to working. Here is how I create it:

dialog = ProgressDialog.show(from, "Posting...", "Uploading...");

Then on UI thread (calling within runOnUiThread), I'm calling:

dialog.setIndeterminate(false);

However, when I inspect after it (both immediately after setting, and in progress handler afterwards which is invoked independently while uploading a file), it's isIndeterminate() method returns true. I've also tried:

dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

But it also didn't change anything (still, indeterminate indicator is spinning instead of a progress bar). I've set it's max to 100, and my progress handler is being invoked with perfectly valid values between 0 and 100, and I'm calling all dialog methods on UI thread, but nothing changes. What am I doing wrong?


Solution

  • You can't change the style of the progress after showing the ProgressBar what you can do is to prepare it first then show it.

    progressDialog = new ProgressDialog(this);
    progressDialog.setTitle("title");
    progressDialog.setMessage("message");
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.show();
    

    OR

    dialog = ProgressDialog.show(from, "Posting...", "Uploading...", false);