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 th
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.
e.g.
MyTask {
// get handle on ProgressBar ViewItem defined in XML (id:progressBar)
ProgressBar progressBar = findViewById(R.id.progressBar);
//starting task, show progress bar
progressBar.setVisibility(View.VISIBLE);
// Do some stuff...
//task done, hide it again
progressBar.setVisibility(View.GONE);
}
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.
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(R.id.progressBar);
Then at the point i want spinning wheel to appear i give command
mprogressBar.setVisibility(View.VISIBLE);
at the point where i want it to disappear .
mprogressBar.setVisibility(View.INVISIBLE);
This is under switch actually. so that as the states in my program change, the progress bar appears and disappears
@reflog: That's not what is needed I guess.
@lostInTransit:
The correct way to achieve this is as follows:
That's it. It works for me on devices with 1.5 to 2.1. Not tried on 2.2.
-Yogesh
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.
It's explained in full in ApiDemos inside the SDK. The example that you want is named: ProgressBar3.java 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).