Android – show an indeterminate progressbar without the dialog-ThrowExceptions

Exception or error:

I want to show my progressbar in the center of the screen when a processing happens on a button click. But I just want the progressbar without the dialog box..

Is there any way I can do this?

How to solve:

It’s explained in full in ApiDemos inside the SDK.
The example that you want is named: and can be found in \ApiDemos\src\com\example\android\apis\view\

Also, if you want to remove the borders of the dialog so that only the progress bar appears you can define the dialog itself as a transparent view/overlay (it’s explained in the examples as well).


If you need no dialog, just put the progressBar in your layout like any other view item, and set the visibility to ‘INVISIBLE’ or even ‘GONE’ by default.

Then just show it whenever you need to by changing it to ‘VISIBLE’ using setVisibility in your code, and re-hide it when the task is done by making it ‘INVISIBLE’ or ‘GONE’ again.


MyTask {

// get handle on ProgressBar ViewItem defined in XML (id:progressBar)

ProgressBar progressBar = findViewById(;

//starting task, show progress bar


// Do some stuff... 

//task done, hide it again



This is a simple version, all done in the UI thread, but this should be easy to adapt if you are using an asynchronous task or thread handlers. Just show, hide, and post any updates to the dialog while you are in the UI thread, and do your long-running task in the background.


That’s not what is needed I guess.


The correct way to achieve this is as follows:

  1. Create ur own dialog
  2. Put progress bar as only view on the dialog
  3. Set dialog window background transparent
  4. Show the dialog.

That’s it. It works for me on devices with 1.5 to 2.1. Not tried on 2.2.



The answer by @Jesse Finnerty solved my issue.
what i did was:

private ProgressBar mprogressBar;

The inside oncreate() just like other buttons and textviews i did,
mprogressBar = (ProgressBar) findViewById(;

Then at the point i want spinning wheel to appear i give command


at the point where i want it to disappear .


This is under switch actually. so that as the states in my program change, the progress bar appears and disappears


There is a great example to do what Yogesh is suggesting at:

How to center progress indicator in ProgressDialog easily (when no title/text passed along)

Credit goes to Macarse for posting it.

Leave a Reply

Your email address will not be published. Required fields are marked *