Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - show an indeterminate progressbar without the dialog

Tags:

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?

like image 406
lostInTransit Avatar asked Apr 01 '09 06:04

lostInTransit


People also ask

What is ProgressBar indeterminate?

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" />

Can you use to display a progress bar in an Android application?

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.


2 Answers

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).

like image 140
reflog Avatar answered Oct 03 '22 06:10

reflog


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.

like image 24
Jesse Finnerty Avatar answered Oct 03 '22 05:10

Jesse Finnerty