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?
Indeterminate mode is the default for progress bar and shows a cyclic animation without a specific amount of progress indicated. The following example shows an indeterminate progress bar: <ProgressBar android:id="@+id/indeterminateBar" android:layout_width="wrap_content" android:layout_height="wrap_content" />
Progress bars are used to show progress of a task. For example, when you are uploading or downloading something from the internet, it is better to show the progress of download/upload to the user. In android there is a class called ProgressDialog that allows you to create progress bar.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With