-2

This is my code I'm not able update the timer in progressbar:

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

        ProgressDialog progressDialog;
        @Override
        protected void onPreExecute() {
            progressDialog = ProgressDialog.show(CurrentHealthActivity.this, "Wait", "getting...");
             this.progressDialog.setIndeterminate(false);
                this.progressDialog.setMax(100);
                this.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                this.progressDialog.setCancelable(false);
            super.onPreExecute();
        }

        @Override
        protected Integer doInBackground(String... params) {
            arrayList=service.getIPList(params[0], params[1]);
            System.out.println("1-result"+arrayList.size());
            return arrayList.size();
        }

        @Override
        protected void onProgressUpdate(Integer... values) {        
             int current = values[0];
                int total = values[1];
         System.out.println("value="+values.toString());
                float percentage = 100 * (float) current / (float) total;

                progressDialog.setProgress((int) percentage);
        }

        @Override
        protected void onPostExecute(Integer result) {
            progressDialog.dismiss();

            if(result > 0){
                System.out.println("3-result"+result);
                fillItemListAdapter();
            }
            else{
                Toast.makeText(getApplicationContext(), "No Record Found", Toast.LENGTH_SHORT).show();
            }
            super.onPostExecute(result);
        }
    }
Pankaj
  • 7,908
  • 6
  • 42
  • 65
Issac Balaji
  • 1,441
  • 1
  • 13
  • 25

1 Answers1

0

You have to use publishProgress() method in doInBackground() method to call onProgressUpdate() method.

        @Override
        protected Integer doInBackground(String... params) {
            arrayList=service.getIPList(params[0], params[1]);
            System.out.println("1-result"+arrayList.size());
            int current = arrayList.get(0);
            int total = arrayList.get(1);
            float percentage = 100 * (float) current / (float) total;
            publishProgress((Integer)percentage);
            return wateverValueToReturn;  
        }

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

                progressDialog.setProgress(progress);
        }
Pankaj
  • 7,908
  • 6
  • 42
  • 65