Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop and start a ProgressBar

I am unable to stop a ProgressBar. Its style is ProgressBarStylesmall. How can I start and stop a circular, small ProgressBar?

like image 261
saqibabbasi Avatar asked Jul 03 '12 15:07

saqibabbasi


People also ask

How do I start a progress bar?

To start a ProgressDialog : progressDialog = ProgressDialog . show(myActivityContext, "ProgressDialog Title", "ProgressDialog Body"); By default the ProgressDialog UI is circular just like you need it.

What is ProgressBar in android?

Android ProgressBar is a graphical view indicator that shows some progress. Android progress bar displays a bar representing the completing of the task. Progress bar in android is useful since it gives the user an idea of time to finish its task.


2 Answers

By default you can make progressBar visible and hide it when not needed like this:

progressBar.setVisibility(View.GONE); 

If you want to control it programatically then you can achieve that with:

progressBar.setVisibility(View.VISIBLE); //to show progressBar.setVisibility(View.GONE); // to hide 

You can even go with ProgressDialog:

private ProgressDialog progressDialog; ...  public void showProgressDialog() {     if (progressDialog == null) {         progressDialog = new ProgressDialog(PhotographerDetailActivity.this);         progressDialog.setIndeterminate(true);         progressDialog.setCancelable(false);     }     progressDialog.setMessage("your message");     progressDialog.show(); }  public void dismissProgressDialog() {     if (progressDialog != null ) {         progressDialog.dismiss();     } 

Hope it will help you.

like image 131
Riten Avatar answered Oct 02 '22 20:10

Riten


You'll need to handle AsyncTasks for this.

/*  * We set the visibility to true. If it was already visible   * there's no need of doing this but we do it for the sake of readability.  */ final ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar1); progressBar.setVisibility(View.VISIBLE); new AsyncTask<Void,Void,Void>(){  //The variables you need to set go here      @Override     protected Void doInBackground(final Void... params){          // Do your loading here. Don't touch any views from here, and then return null          return null;     }       @Override     protected void onPostExecute(final Void result){          // Update your views here          progressBar.setVisibility(View.GONE);     } }.execute() 
like image 22
Charlie-Blake Avatar answered Oct 02 '22 22:10

Charlie-Blake