0

我的 asynctask 没有进入 onProgressUpdate。为什么?我将在 asynctask 中创建进度条。下面是我使用进度条显示上传图像的代码。

public static class RegisterDataEngineForPost extends AsyncTask<MultipartEntity, integer, String>{


    ProgressBar ProgressBarUpload;


    public void setmCurrentPhotoPath(ProgressBarUploadb) {

        ProgressBarUpload = ProgressBarUploadb;
    }

    @Override
    protected void onProgressUpdate(integer... values) {


    }

    @Override
    protected void onPreExecute() {
        ProgressBarUpload.setProgress(0);
    }


    @Override
    protected String doInBackground(MultipartEntity... params) {


    }

    @Override
    protected void onPostExecute(String result) {

        }
    }
}
4

2 回答 2

2

使用http://developer.android.com/reference/android/os/AsyncTask.html#publishProgress(Progress...)

手动,Android不会凭空知道你的进度,你需要自己确定。

于 2013-10-08T08:07:25.897 回答
2

你必须调用 publishProgress(progress_value) 来更新进度

public static class RegisterDataEngineForPost extends AsyncTask<MultipartEntity, integer, String>{


ProgressBar ProgressBarUpload;


public void setmCurrentPhotoPath(ProgressBarUploadb) {

    ProgressBarUpload = ProgressBarUploadb;
}

@Override
protected void onProgressUpdate(integer... values) {


}

@Override
protected void onPreExecute() {
    ProgressBarUpload.setProgress(0);
}


@Override
protected String doInBackground(MultipartEntity... params) {
      //do some task and update the progress
   publishProgress(progress_value);

}

@Override
protected void onPostExecute(String result) {

    }
}
}
于 2013-10-08T08:59:07.103 回答