My activity have a ProgressBar. When start activity, I\'ll check value get from another place and update to ProgressBar. Here\'s my code:
final ProgressBar p
I usually use this code:
private int mProgressStatus;
private Handler mHandler = new Handler();
public void startProgress(View view) {
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.horizontal_progress);
mProgressStatus = 0;
progressBar.setProgress(mProgressStatus);
//progressBar.setVisibility(View.VISIBLE);
new AsyncTask() {
@Override
protected Void doInBackground(final Void... params) {
while (mProgressStatus < 100) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
mProgressStatus += 15;
mHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(mProgressStatus);
}
});
}
return null;
}
}.execute();
}
Hope this helps