views:

53

answers:

1

Hi,

When I press a button I would like to have a progressbar showing up so I inserted this code:

progDailog = ProgressDialog.show(this, "Downloading data", "please wait....", true);

But the progressDialog is not showing at all. Why? What more do I need to do to show it?

/M

+1  A: 

If you want a progress bar to display while some work is being performed, you'll need to use another thread for the task, so it doesn't block the UI. That's the 'why' of this question; the progress dialog is blocked by the data download, so it doesn't get to display itself.

I'd go with AsyncTask from the Android API.

The following is a subclass from within the calling Activity:

private class myTask extends AsyncTask<Void, Void, Void> {
    private ProgressDialog progDialog;

    onPreExecute() {
        progDailog = ProgressDialog.show(this, "Downloading data", "please wait....", true);
    }

    doInBackground(Void... params) {
        // Here's where the work should happen
    }

    onPostExecute(Void result) {
        // Close the dialog, pass results back, whatever...
    }
}

Please excuse any code errors - I'm not where I can access the SDK.

kiswa
So... did this answer help?
kiswa
Thank youSorry about getting back so late
Maeron
No problem. If I did answer the question, please mark it so others that find your question know this helped.
kiswa