0

how to show progress bar while loading images. I have tried the code given below

 Picasso.with(getActivity())
                    .load(stage1ImageURL)
                    .placeholder(android.R.layout.simple_spinner_item)
                    .error(R.drawable.no_image).into(stage1ImageView);
yuva ツ
  • 3,707
  • 9
  • 50
  • 78
user3800661
  • 49
  • 1
  • 3

3 Answers3

0

Take a look at the official docs how to deal with a progress bar.

In your case, you have to write an AsyncTask, which starts the dialog in onPreExecute() and ends in onPostExecute().

Bobbelinio
  • 134
  • 1
  • 8
0

Try this, it uses AsyncTask:

public class LoadData extends AsyncTask<Void, Void, Void> {
    ProgressDialog progressDialog;
    //declare other objects as per your need
    @Override
    protected void onPreExecute()
    {
        //show loading dialog
        progressDialog= ProgressDialog.show(YourActivity.this, "Progress Dialog Title Text","Process Description Text", true);

        //do initialization of required objects objects here                
    };      
    @Override
    protected Void doInBackground(Void... params)
    {   

         //do loading operation here  
        return null;
    }       
    @Override
    protected void onPostExecute(Void result)
    {
        super.onPostExecute(result);
        progressDialog.dismiss();
    };
}

You can call this using from your onCreate():

LoadData task = new LoadData();
task.execute();
Sagar Pilkhwal
  • 3,998
  • 2
  • 25
  • 77
0

You have to use

progressBar.setVisibility(View.VISIBLE);

to show progressBar. And to hide it,

progressBar.setVisibility(View.GONE);

Follow this link for complete code.

Community
  • 1
  • 1
Paritosh
  • 2,097
  • 3
  • 30
  • 42