Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

progressdialog - How do I show and then remove an android progress dialog

I can get a progress bar to appear with the following code

pd = ProgressDialog.show(myActivity.this, "", "Loading. Please wait...", true);

straight forward, but once I have the code execute I want it to go away, but when I run the dismiss method after I never see the dialog box show at all.

Heres the code in context which is wrapped in oncreate

pd = ProgressDialog.show(myActivity.this, "", "Loading. Please wait...", true);
runCode();  
setListAdapter(new CustomAdapter(myActivity.this)); 
pd.dismiss();

I thought you can show/dismiss progress dialog's anywhere in the activity but I must be wrong.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

here is the code that I got to work

private class UpdateFeedTask extends AsyncTask<MyActivity, Void, Void> {

    private ProgressDialog mDialog;

    protected void onPreExecute() {
        Log.d(TAG, " pre execute async");
        mDialog = ProgressDialog.show(MyActivity.this,"Please wait...", "Retrieving data ...", true);

    }

    protected void onProgressUpdate(Void... progress) {
        Log.d(TAG, " progress async");     
    }

    @Override
    protected Void doInBackground(MyActivity... params) {
        // TODO Auto-generated method stub
        return null;
    }

    protected void onPostExecute(Void result) {
        Log.d(TAG, " post execute async");
        mDialog.dismiss();
    }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...