title: ProgressDialog in android
body: <p>This is my activity code.. here I'm fetching data from the database through JSON and PHP...</p>
  
  <p>How can I display a progessDialog when the data is loading?</p>
  
  <p>Here is my activity code:</p>
  
  <pre><code>package org.postandget;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.util.ArrayList;
  import java.util.HashMap;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.ClientProtocolException;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.json.*;
  import android.app.Activity;
  import android.app.ProgressDialog;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.TextView;
  
  public class main extends Activity {
      static TextView tv;
      static String text;
      ProgressDialog progressDialog;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);       
          tv  = (TextView)findViewById(R.id.textview);
          text    = "";
          tv.setText("hi parthi");                
         new main.execute();
      }
  
      public static void postData(Object JSONfunctions) throws JSONException{
          // Create a new HttpClient and Post Header
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("http://eeeee.com/ee/login.php");      
          JSONObject json = new JSONObject();
          try {
              // JSON data:           
              json.put("name", "Fahmi Rahman");
              json.put("position", "sysdev");         
              JSONArray postjson=new JSONArray();
              postjson.put(json);
              // Post the data:
              httppost.setHeader("json",json.toString());
              httppost.getParams().setParameter("jsonpost",postjson);
  
              // Execute HTTP Post Request
              System.out.print(json);
              HttpResponse response = httpclient.execute(httppost);
              // for JSON:
              if(response != null)
              {
                  InputStream is = response.getEntity().getContent();
                  BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                  StringBuilder sb = new StringBuilder();
                  String line = null;
                  try {
                      while ((line = reader.readLine()) != null) {
                          sb.append(line + "\n");
                      }
                  } catch (IOException e) {
                      e.printStackTrace();
                  } finally {
                      try {
                          is.close();
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
                  }
                  text = sb.toString();
              }
  
              tv.setText(text);
  
          }catch (ClientProtocolException e) {
              // TODO Auto-generated catch block
          } catch (IOException e) {
              // TODO Auto-generated catch block
          }
      }
  
      private class xyz extends AsyncTask&lt;Void, Void, Void&gt; {
          private final ProgressDialog dialog = new ProgressDialog(main.this);
  
          protected void onPreExecute() {
              this.dialog.setMessage("Please Wait...");
              this.dialog.show();
              //code which load at prefix time
              try {
                 main.postData(null);          
              } catch (JSONException e) {
                  e.printStackTrace();        }
          }
  
          @Override
          protected Void doInBackground(Void... arg0) {
  
                  // make code which you want in background
  
              return null;
          }
  
          protected void onPostExecute(final Void unused) {
              if (this.dialog.isShowing()) {
                  this.dialog.dismiss();
  
              }
  
          }
      }
  }
  </code></pre>