how to add "please wait" with progress bar till it loads the data?
<p>my whole application is based on php connection and mysql data processing. since it takes a bit of a time to load the data, currently users can not see what is happening and they goes and click buttons thinking nothing is happening and without waiting for the data to be load.</p>

<p>as a solution for that i want to add "Please wait till data load" with a progress bar. </p>

<p>how can i do that to the following code.</p>

<p>i tried with Async task and tutorials but cound't get the hang of it.</p>

<p>thank you,</p>

<pre><code>  public class Activity_YourFriendsWith_Class extends Activity {

public String PREFS_NAME = "MyPrefsFile";
public String PREFS_USERID = "prefsUserId";

private static final String TAG_Name = "fname";
private static final String TAG_LName = "lname";

String result = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_yourfriendswith);

    SharedPreferences pref = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);

    String userId = pref.getString(PREFS_USERID, "");

    Button back = (Button) findViewById(R.id.addback);
    back.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent();
            intent.setClass(getApplication(), Activity_MyProfile_Class.class);
            startActivity(intent);
            finish();
        }
    });

    Button addfrnds = (Button) findViewById(R.id.addfrnds);
    addfrnds.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent inti = new Intent();
            inti.setClass(Activity_YourFriendsWith_Class.this,
                    Activity_AddFreinds_Class.class);
            startActivity(inti);
        }
    });



    InputStream is = null;

    ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
    nameValuePairs.add(new BasicNameValuePair("user_id", userId));
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                "http://hopscriber.com/friendshopscriber.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();

    } catch (Exception e) {
        Log.e("log_tag", "Error in http connection " + e.toString());
    }
    // convert response to string
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        result = sb.toString();
    } catch (Exception e) {
        Log.e("log_tag", "Error converting result " + e.toString());
    }

    ProgressTask task = new ProgressTask();
    task.execute();

}
private class ProgressTask extends AsyncTask&lt;String, Void, Boolean&gt; {

           private ProgressDialog pd;
        private Activity activity;

        public void LoadDataTask(Activity activity){

            this.activity = activity;
        }


    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        pd = ProgressDialog.show(activity,
                    "Please wait", "Loading datas", true);
    }

    @Override
    protected Boolean doInBackground(String... arg0) {
        // TODO Auto-generated method stub
        // parse json data
        try {

            ArrayList&lt;HashMap&lt;String, String&gt;&gt; placelist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
            JSONArray jArray = new JSONArray(result);
            if (jArray != null) {
                for (int i = 0; i &lt; jArray.length(); i++) {
                    JSONObject json_data = jArray.getJSONObject(i);
                    HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();

                    map.put(TAG_Name, json_data.getString("fname"));
                    map.put(TAG_LName, json_data.getString("lname"));

                    placelist.add(map);
                }
            }
            ListView list = (ListView) findViewById(R.id.frndslist);

            ListAdapter adapter = new SimpleAdapter(activity, placelist,
                    R.layout.listrow_yourfriendswith, new String[] { TAG_Name,
                            TAG_LName }, new int[] {
                            R.id.fname, R.id.lname });
            list.setAdapter(adapter);

        } catch (JSONException e1) {
            ListView list = (ListView) findViewById(R.id.frndslist);
            list.setEmptyView(findViewById(R.id.fempty));
        }
        return null;
    }

    }



}
</code></pre>

<p>Logcat</p>

<pre><code>08-16 16:26:52.748: E/AndroidRuntime(905): java.lang.RuntimeException: Unable to start activity ComponentInfo{hopscriber.com/hopscriber.com.Activity_YourFriendsWith_Class}: java.lang.NullPointerException
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.os.Looper.loop(Looper.java:130)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.ActivityThread.main(ActivityThread.java:3683)
08-16 16:26:52.748: E/AndroidRuntime(905):  at java.lang.reflect.Method.invokeNative(Native Method)
08-16 16:26:52.748: E/AndroidRuntime(905):  at java.lang.reflect.Method.invoke(Method.java:507)
08-16 16:26:52.748: E/AndroidRuntime(905):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-16 16:26:52.748: E/AndroidRuntime(905):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-16 16:26:52.748: E/AndroidRuntime(905):  at dalvik.system.NativeStart.main(Native Method)
08-16 16:26:52.748: E/AndroidRuntime(905): Caused by: java.lang.NullPointerException
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.Dialog.&lt;init&gt;(Dialog.java:141)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.AlertDialog.&lt;init&gt;(AlertDialog.java:63)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.ProgressDialog.&lt;init&gt;(ProgressDialog.java:80)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.ProgressDialog.&lt;init&gt;(ProgressDialog.java:76)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.ProgressDialog.show(ProgressDialog.java:101)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.ProgressDialog.show(ProgressDialog.java:90)
08-16 16:26:52.748: E/AndroidRuntime(905):  at hopscriber.com.Activity_YourFriendsWith_Class$ProgressTask.onPreExecute(Activity_YourFriendsWith_Class.java:132)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.os.AsyncTask.execute(AsyncTask.java:391)
08-16 16:26:52.748: E/AndroidRuntime(905):  at hopscriber.com.Activity_YourFriendsWith_Class.onCreate(Activity_YourFriendsWith_Class.java:81)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-16 16:26:52.748: E/AndroidRuntime(905):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
</code></pre>
