Question

i need to set a circular progress bar while doing some stuff. I've already done this:

progressBar = (ProgressBar) findViewById(R.id.progressBar1);

in my OnCreate() and then called progressBar.setVisibility(View.Visible) and View.Gone after doing things, but the progressBar is not displaying.

 progressBar.setVisibility(View.VISIBLE);
 thumbnailAux = doThings(thumbnail);
 image.setImageBitmap(thumbnailAux);
 progressBar.setVisibility(View.GONE);

The method doThings takes a few seconds to complete execute. Please help!!

No correct solution

OTHER TIPS

Android has a Predefined class for a progress bar, its in a class called ProgressDialog. It looks like this:

enter image description here

You can add this codes in your onCreate() and set the state of the progressDialog like this:

ProgressDialog progress = new ProgressDialog(this);

Also add this following code to a background Thread.

private class ProgressThread extends Thread {

    private ProgressDialog progress;

    public ProgressThread(Context context, ProgressDialog progress) {
        progress.setMessage("Downloading Music :) ");
        progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progress.setIndeterminate(true);
    }

    public void run() {
        // update progressbar here
    }
}

For more details you can check the Android API Documentation here

This site has a full application demo about it, you might want to check it out.

You can apply AsyncTask for this case.

You can refer more information from this link.

You can add progressDialog to onPreExecute method and then dismiss in onPostExecute method.

// Async Task to access the web
    private class YourTask extends AsyncTask<String, Void, String> {
            ProgressDialog myPd_bar;
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            myPd_bar=new ProgressDialog(class.this);
            myPd_bar.setMessage("Loading....");
            myPd_bar.setTitle(Title);
            myPd_bar.show();
            super.onPreExecute();
        }

        @Override
        protected String doInBackground(String... params) {

             //Things should do in, until progress bar close
             return null;

        }

        @Override
        protected void onPostExecute(String result) {

            myPd_bar.dismiss();
        }
    }// end async task
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top