My actual task is getting completed however I am not getting any increase in the progress status of my progress bar even if i call the progress dialog..?can anyone say where I did wrong?
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;
}
}
below is the method from which I call the 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);
}
Your integer math is broken. The line
will always yield
0
because integer division truncates to just the integer portion.To fix it, just use floats instead. Specifically: