0

Possible Duplicate:
How to display progress dialog before starting an activity in Android?

this is my itemDetails extends Activity class and onOkClick is the method. But when I press the ok button i.e call the method no ProgressDialog shows up. But the Toast messages show correctly.

I tried using getApplicationContext() in the Context parameter of the ProgressDialog.show() method, but it is not working. Sorry for this naive question.

    public void onOkClick(View v){

        ProgressDialog pleaseWait = ProgressDialog.show(itemDetails.this, "Uploading..", "Please wait for a while...", true);

            //...........
            HttpData httpData = HttpRequest.post("http://www.abc.com/accessServer.php", "");
            //...........
            pleaseWaitGallery.dismiss();
        if(HttpPostTesting.storestring.contains("successful")){
            Toast.makeText(getApplicationContext(), "Uploading Complete", Toast.LENGTH_LONG).show();
        }
        else {
            Toast.makeText(getApplicationContext(), "Uploading Failed!", Toast.LENGTH_LONG).show();
        }
    }
Community
  • 1
  • 1
ruben
  • 1,745
  • 5
  • 25
  • 47

1 Answers1

2

You want to use an AsyncTask to display a ProgressDialog while doing operations in the background.

Try this answer, which contains a full code sample.

With your code, you are actually showing and dismissing the dialog before the system has a chance to draw it.

Community
  • 1
  • 1
Matthew
  • 44,826
  • 10
  • 98
  • 87