2012-01-25 13 views
2

私の実際のタスクは完了していますが、進行状況ダイアログを呼び出してもプログレスバーの進行状況が増えません。以下AsyncTask publishProgressが私のProgressDialogを更新しない

class A extends AsyncTask<File[],Integer,Void> 
       { 
        private Context cnt; 
         int count=0; 
        @Override 
        protected void onPreExecute() { 
         pd = new ProgressDialog(cnt); 
          pd.setMessage("Matching progress"); 
          pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
          pd.setMax(100); 
          pd.setCancelable(false); 
          pd.setProgress(0); 
          pd.show(); 
        } 
        A(Context context) 
        { 
         cnt=context; 
        } 

        protected Void doInBackground(File[]... params) { 
         // TODO Auto-generated method stub 
         File[] newfiles=params[0]; 
         File[] temp=null; 
         int progress=0; 
         int dircnt=0; 
         int numberofdir=newfiles.length; 
         for(File b:newfiles) 
         { 


          count=0; 
          dirname=b.getName(); 
          if(b.isDirectory()) 
          { 

           temp=b.listFiles(); 
          } 
          for(File a:temp) 
          { 
           gest=dotask.batchprocess(a.getPath()); 
           if(gest!=null) 
            System.out.println("success"); 
           String name=dirname+"_"+count; 
           saveGesture(name, gest); 
           count++; 

          } 
          dircnt++; 
          progress=(int)((dircnt/numberofdir)*100); 
          publishProgress(progress); 


         } 


         return null; 
        } 
        @Override 
        protected void onProgressUpdate(Integer... values) { 
         // increment progress bar by progress value 
         pd.setProgress(values[0]); 


       } 
        protected void onPostExecute() { 
         pd.hide(); 
         pd=null; 
        } 
    } 

私はAsyncClassを呼び出し、そこからメソッドです。

public void addgestures() 
    { 
       cView.postInvalidate(); 
       dotask.setH(cView.getH()); 
       dotask.setW(cView.getW()); 

       count=0; 
       files=null; 
       /*if(dir.isDirectory()) 
       { 
        files=dir.listFiles(); 
       }*/ 
       files=dir.listFiles(); 
       for(int i=0;i<files.length;i++) 
       { 
        System.out.println(files[i].getPath()); 
       } 




       A a=new A(this); 
       a.execute(files); 



      } 

答えて

1

整数計算が壊れています。整数除算がちょうど整数部分に切り捨てためライン

progress=(int)((dircnt/numberofdir)*100); 

は常に0をもたらします。

修正するには、代わりに浮動小数点数を使用してください。具体的には、

float dircnt=0; 
float numberofdir=newfiles.length; 
関連する問題