progressbar while loading AlerDialogBox
<p>i have a button that display a AlertDialog in witch i do some calculations and it takes sometime, i would like to show a progressbar while doing the calculations.
this is what i have so far but it is not working like i want.
the dialog show but despair before the AlertDialog finished doing the calculations  </p>

<p>this the code </p>

<pre><code>public void OnClick(View v) {

    try {

        new DownloadingProgressTask().execute();

    } catch (Exception e) {

        Log.v("Exception", e.toString());
    }

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

    private ProgressDialog dialog = new ProgressDialog(Calculations.this);

    /** progress dialog to show user that the backup is processing. */

    /** application context. */

    protected void onPreExecute() {
        this.dialog.setMessage("Please wait");
        this.dialog.show();

    }

    @SuppressWarnings("deprecation")
    protected Boolean doInBackground(final String... args) {
        try {

            LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            inflatedview = layoutInflater.inflate(R.layout.calculationhelp, null);

            final TextView result = (TextView) inflatedview.findViewById(R.id.textViewresult);
            titleAlerDialog = (TextView) inflatedview.findViewById(R.id.textViewTitle);
            messageAlerDialog = (TextView) inflatedview.findViewById(R.id.textViewMsg);

            separated = help.toString().split("#");

            Resources r = getResources();
            Bundle extras = getIntent().getExtras();
            if (extras != null) {

                        tableResults = r.getStringArray(R.array.Calculo1Results1);
                        result.setText(r.getString(R.string.calculo1results1));
            }

            titleAlerDialog.setText(separated[0]);

            messageAlerDialog.setText(separated[1].toString());


            /* Find Tablelayout defined in main.xml */
            TableLayout tl = (TableLayout) inflatedview.findViewById(R.id.myTableLayout);
            tl.setColumnStretchable(0, true);
            tl.setColumnStretchable(1, true);
            tl.setColumnStretchable(2, true);

            for (int i = 0; i &lt; tableResults.length; i++) {
                /* Create a new row to be added. */
                TableRow tr = new TableRow(Calculations.this);
                tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

                /* Create a cell1 to be the row-content. */
                TextView cell1 = new TextView(Calculations.this);
                TextView cell2 = new TextView(Calculations.this);
                TextView cell3 = new TextView(Calculations.this);

                String[] cells = tableResults[i].toString().split("@");

                cell1.setWidth(130);
                cell1.setGravity(Gravity.CENTER_VERTICAL
                        | Gravity.CENTER_HORIZONTAL);
                cell1.setText(cells[0].toString());
                cell1.setBackgroundResource(R.drawable.celda_cuerpo);
                cell1.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

                cell2.setWidth(130);
                cell2.setGravity(Gravity.CENTER_VERTICAL
                        | Gravity.CENTER_HORIZONTAL);
                cell2.setText(cells[1].toString());
                cell2.setBackgroundResource(R.drawable.celda_cuerpo);
                cell2.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

                cell3.setWidth(130);
                cell3.setGravity(Gravity.CENTER_VERTICAL
                        | Gravity.CENTER_HORIZONTAL);
                cell3.setText(cells[2].toString());
                cell3.setBackgroundResource(R.drawable.celda_cuerpo);
                cell3.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

                /* Add cell1 to row. */
                tr.addView(cell1);
                tr.addView(cell2);
                tr.addView(cell3);

                /* Add row to TableLayout. */
                tl.addView(tr, new TableLayout.LayoutParams(
                        LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

            }
            //dialog.dismiss();
            return true;
        } catch (Exception e) {
            Log.e("tag", "error", e);
            return false;
        }
    }

@Override
protected void onPostExecute(final Boolean success) {

if (dialog.isShowing()) {
    dialog.dismiss();
}

if (success) {
    AlertDialog.Builder dialog1 = new AlertDialog.Builder(Calculations.this);
    dialog1.setNegativeButton("Close",
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface arg0, int arg1) {

                }
            });

    dialog1.setView(inflatedview);
    final AlertDialog alert = dialog1.create();
    alert.requestWindowFeature(Window.FEATURE_NO_TITLE);

    alert.show();



    ((Button) alert.findViewById(android.R.id.button2))
            .setBackgroundResource(R.drawable.custom_button_red);
    ((Button) alert.findViewById(android.R.id.button2))
            .setTextColor(Color.WHITE);


} else {
    Toast.makeText(Calculations.this, "Error", Toast.LENGTH_LONG)
            .show();
}
}

}
</code></pre>

<p>any help would be appreciated
best regards
HP</p>
