not able to update the progress from backgound
akash09766 opened this issue · comments
Akash Wangalwar commented
I passed the reference of the view to AsyncTask and and doing progress update in the onProgressUpdate() method , but i got the following error ,
Animators may only be run on Looper threads at
how to update the progress of view from asynctask
Lopez Mikhael commented
It works very well I do not understand your problem.
An example of implementation in a AsyncTask:
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.mikhaellopez.circularfillableloaders.CircularFillableLoaders;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CircularFillableLoaders circularFillableLoaders = (CircularFillableLoaders) findViewById(R.id.circularFillableLoaders);
new CircularFillableLoadersAsyncTask(circularFillableLoaders).execute();
}
private class CircularFillableLoadersAsyncTask extends AsyncTask<Void, Integer, Void> {
private CircularFillableLoaders mCircularFillableLoaders;
public CircularFillableLoadersAsyncTask(CircularFillableLoaders circularFillableLoaders) {
mCircularFillableLoaders = circularFillableLoaders;
}
@Override
protected void onProgressUpdate(Integer... values) {
int progress = values[0];
mCircularFillableLoaders.setProgress(progress);
}
@Override
protected Void doInBackground(Void... params) {
for (int progress = 0; progress < 100; progress++) {
try {
Thread.sleep(200);
publishProgress(progress);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return null;
}
}
}