如何在Android中的Web服务中的android异步任务中获得进度更新?

时间:2014-03-28 09:49:51

标签: android android-asynctask progressdialog

首先在这个Web服务中没有文件或图像上传或下载,只是注册Web服务,在调用此API时,我想显示进度更新?这该怎么做?我使用下面的代码:

private class DetectLocation extends AsyncTask<String, String, String> {

        private JSONObject response, jPostObject;
        private String status, data;
        private ImageView iv1, iv2, iv3,ivAnim1, ivAnim2, ivAnim3;


        public DetectLocation(ImageView iv1, ImageView iv2, ImageView iv3,
                JSONObject obj,ImageView ivAnim1, ImageView ivAnim2, ImageView ivAnim3) {
            this.jPostObject = obj;
            this.iv1 = iv1;
            this.iv2 = iv2;
            this.iv3 = iv3;

            this.ivAnim1 = ivAnim1;
            this.ivAnim2 = ivAnim2;
            this.ivAnim3 = ivAnim3;
        }
        @Override
        protected void onProgressUpdate(String... values) {
            super.onProgressUpdate(values);

        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

        }

        @Override
        protected String doInBackground(String... args) {
            try {

                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("data", jPostObject
                        .toString()));
                response = WebAPIRequest.makeJsonObjHttpRequest(
                        URLS.DETECT_LOCATION, "POST", params);
                status = response.getString("status");
                UTILS.Log_e(TAG, response.toString());
                data = response.getString("data");
            } catch (Exception e) {
                UTILS.Log_e(TAG + "-Exception", "" + e);
            }

            return null;
        }

        @Override
        protected void onPostExecute(String args) {

        }
    }  

1 个答案:

答案 0 :(得分:0)

这是你的进度更新。

   @Override
    protected void onPreExecute() {
        pd.setMessage("Please wait...");
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setCancelable(false);
        pd.show();

    }

            @Override
    protected void onProgressUpdate(Integer... progress) {

        pd.setProgress((int) (progress[0]));
    }