title: Android :showing progress dialog
body: <p>I am making an android application that gets updated. For this I need a simple function that can download a file and show the current progress in a ProgressDialog. I know how to do the download the file, but I'm not sure how to display the current progress.I am using the following method for downloading images. </p>
  
  <pre><code>public Bitmap DownloadFile(String url){
  URL myFileUrl;
  Bitmap bitmap=null;
  try {
  myFileUrl = new URL(imageUrl);
      HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
      conn.setDoInput(true);
      conn.setConnectTimeout(10000);
      conn.setReadTimeout(10000);
      conn.connect();
      InputStream is = conn.getInputStream();
      bmImg = BitmapFactory.decodeStream(is);
      bitmap = BitmapFactory.decodeStream((InputStream) new URL(  
           imageUrl).getContent()); 
      bitmap = Bitmap.createScaledBitmap(bitmap,80 , 80, true);
      System.out.println("name of butmap"+bitmap.toString());
  
  } catch (Exception e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
  return bitmap;
  
  }
  </code></pre>
  
  <p>And following is my async task class :</p>
  
  <pre><code>    public class BackgroundAsyncTask extends AsyncTask&lt;String, Integer, Bitmap&gt; {
  
     int myProgress;
  
     @Override
  
      protected void onPostExecute(Bitmap result) {
      dialog.dismiss();
      iv.setVisibility(View.VISIBLE);
      iv.setImageBitmap(result);
      System.out.println("bbbbbbbbb");
      System.out.println("post execute");
      }
  
  @Override
  protected void onPreExecute() {
      System.out.println("pre execute");
      dialog = ProgressDialog.show(ProfileNormalUserPhotos.this, "Loading...", "Please wait...");
  
  }
  
  @Override
  protected Bitmap doInBackground(String...paths) {
      System.out.println(imageUrl+"  imageurl");
      return DownloadFile(imageUrl);
  
      }
  @Override
  protected void onProgressUpdate(Integer... values) {
      // TODO Auto-generated method stub
          progressBar.setProgress(values[0]);
  }
  
  }
  </code></pre>
  
  <p>and i am calling the method in the following adapter class :</p>
  
  <pre><code>    public class ImageAdapter extends BaseAdapter {  
         Context mContext;
     public String[] stringOnTextView;
  
       public ImageAdapter(Context c) {  
         mContext = c;  
       }  
  
  public ImageAdapter(Context Context,
      String[] stringOnTextView) {
      this.mContext=Context;
      this.stringOnTextView=stringOnTextView;
  }
  
  public int getCount() {  
        return stringOnTextView.length;  
       }  
  
  
  public Object getItem(int position) {  
        return null;  
       }  
  
       public long getItemId(int position) {  
        return position;  
       }  
  
  
       public View getView(int position, View convertView, ViewGroup parent) {
           View v = null;
          if(convertView==null){
  
              try{
  
              {
                    LayoutInflater li = getLayoutInflater();
                    v = li.inflate(R.layout.icon, null);
                    TextView tv = (TextView)v.findViewById(R.id.text);
                    tv.setText("Profile Image "+(position+1));
                     iv= (ImageView)v.findViewById(R.id.image);
  
                     imageUrl = "http://ondamove.it/English/images/users/";
                    imageUrl=imageUrl+stringOnTextView[position];
                     new BackgroundAsyncTask().execute(imageUrl);
  
  
                     }
             }catch (Exception e) {
              e.printStackTrace();
              System.out.println(e);
          }
          }
          else
          {
              try{
              v = convertView;}
              catch(Exception e){
                  System.out.println(e);
              }
          }
          return v;
      }
  }
  </code></pre>
  
  <p>I need to download 9 images but the problem i am facing is that it only shows the last image and progress dialog goes into infinite loop.</p>
  
  <p>Can anyone tell me over how to resolve thios issue.</p>
  
  <p>Thanks</p>