0

編集:問題は解決しました。グローバルにします。私は今、フェイスパームをやっています。ありがとう!

以下は、AsyncTaskを拡張するクラスからのスニペットです。preExecute()メソッドでprogressDialogを開始し、progressDialog.dismiss();を実行したい。postExecute()メソッドで。私が見つけたすべての例は、以下のようにそれを行うと言っています。私が抱えている問題は、ダイアログがonPostExecuteのスコープ外にあることです。これは予想されますが、すべての例でこのようになっているようです。また、インポート時に、インポートが使用されていないことを示す小さな警告サインがあることに気付きました。このProgressDialogは機能する必要がありますか?私はそれを回す必要がありますか?

import android.app.ProgressDialog;
...

protected void onPostExecute(Bitmap image){//error when doing this in resetDisplay.... onPostExecute is invoked by the ui thread so this may be why it works here and not in resetDisplay
                    ImageView imageView=(ImageView) parent.findViewById(R.id.imageDisplay);
                    imageView.setImageBitmap(image);

                    dialog.dismiss();

                }
protected void onPreExecute(){
                    ProgressDialog dialog=ProgressDialog.show(parent, "Loading", "Loading the image of the day");
                }
4

3 に答える 3

2

以下のコードを参照してください

private class ProgressTask extends AsyncTask<String, Void, Boolean> {

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

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

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

    protected Boolean doInBackground(final String... args) {
        try {

            /**
             * Fetch the RSS Feeds from URL
             */
            Utilities.arrayRSS = objRSSFeed
                    .FetchRSSFeeds(Constants.Feed_URL);
            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) {
            // display UI
            UpdateDisplay();
        }
    }
}
于 2012-07-13T10:36:49.833 に答える
1
class YourClass extends AsyncTask<...>
{
    ProgressDialog dialog;
    Protected void onPreExecute(){
        // create dialog here
       dialog= new ProgressDialog (...);
    }
    protected void onPostExecute(Bitmap image){
        //
        dialog.dismiss();
    }
}
于 2012-07-13T10:26:14.767 に答える
0

ProgressDialog dialogアクティビティでダイアログを宣言する外部を宣言してからonPreExecute() 、preExecute()メソッドとpostExecute()メソッドで使用する必要があります。
アクティビティまたは非同期タスク内でこのように宣言します

ProgressDialog dialog=new Progress Dialog(YourActivity.this);

次に、onPreExecute()のダイアログを次のように使用します

 dialog.setMessage("Your Messgae");
 dialog.show();

およびonPostExecute()で

dialog.dismiss();
于 2012-07-13T10:25:35.963 に答える