How to stop and start a ProgressBar

saqibabbasi picture saqibabbasi · Jul 3, 2012 · Viewed 55.9k times · Source

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

Answer

Riten picture Riten · Jul 20, 2016

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.