Reputation: 11
Progress dialog spinner wheel stops spinning while doing the actual work. How can I make it continually spin the wheel while when my other work is going on.......
progressdialog.setMessage("Please wait. . .");
progressdialog.setCancelable(false);
progressdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressdialog.show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
loadFormView(m_table, m_rLayout, m_param);
}
});
progressdialog.dismiss();
}
}, 100);
Upvotes: 0
Views: 407
Reputation: 1221
This might work for you. Try Doing this way:
progressdialog.setMessage("Please wait. . .");
progressdialog.setCancelable(false);
progressdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressdialog.show();
final Handler h = new Handler.postDelayed(new Runnable() {
public void handleMessage(Message message) {
progressdialog.dismiss();
}
};
Thread checkUpdate = new Thread() {
public void run() {
// YOUR WORK
h.sendEmptyMessage(0);
}
}, 1000);
checkUpdate.start();
Upvotes: 0
Reputation: 57
https://developer.android.com/reference/android/os/AsyncTask.html
Here's an example how to use an async task in your case (code is not tested but something along those lines):
private class LoadTask extends AsyncTask<Void, Void, Void> {
protected void onPreExecute(){
progressdialog.show();
}
protected void doInBackground(Void params) {
loadFormView(m_table, m_rLayout, m_param);
return void;
}
protected void onPostExecute(Void result) {
progressdialog.dismiss();
}
}
//start the task
new LoadTask().execute();
Upvotes: 1
Reputation: 10155
If loadFormView
is your "work", that needs to happen on a background thread somehow (thread, intent service, async task, etc).
Right now you're running that "work" on the UI thread, which will block the progress spinning animation.
Upvotes: 1