对话框在Asynctask中没有改变

时间:2016-08-08 16:35:56

标签: android android-asynctask

我试图更新Asynctask的进度条,但它没有改变。从doInbackground我将值传递给onProgreessUpdate它已经过了那里但是这些变化并没有反映出来在progreesdailog。

请看看并告诉我它发生的原因。

Asynctask类

class Export extends AsyncTask<String, Integer, String> {

        ProgressDialog dialog;

        public Export() {

            dialog = new ProgressDialog(InventoryCount.this);
            dialog.setCancelable(false);

        }

        protected void onPreExecute() {
            super.onPreExecute();
            dialog.setMessage("Please wait while exporting the workSheet..");
            dialog.show();
            dialog.setProgress(0);
            dialog.setMax(100);
        }
protected String doInBackground(String... results) {
            String result = "";
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                    .permitAll().build();
            StrictMode.setThreadPolicy(policy);

            MIS_Setting mis_setting = new MIS_Setting();
            dbhelper.getReadableDatabase();
            mis_setting = dbhelper.getSetting();
            dbhelper.close();
            String ipAddress = mis_setting.getIpAddress();

            String F_URL = "http://" + ipAddress
                    + "/MISWCFService/Service.svc/PutMIC";

            dbhelper.getReadableDatabase();
            int Count = GetCount();
            dbhelper.close();
            int length = Count / 5;

            for (int i = 0; i <= length; i++) {
                int progress=(int) ((i / (float) (Count / 5)) * 100);
                publishProgress(progress);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
              }
            }
protected void onProgressUpdate(Integer... progress) {
            //super.onProgressUpdate(progress);
            //dialog.setProgress(progress[0]);;
            // setProgress(progress[0]);
             super.onProgressUpdate(progress);
                // Update the ProgressBar
                dialog.setProgress(progress[0]);
        }

        protected void onPostExecute(String result) {

            if (result.equals("success")) {
                dialog.dismiss();
//Some other stuffs
               }
}
}

0 个答案:

没有答案