Reputation: 349
I try to use progressDialog in Button
click ,but I have android.view.windowmanager$badtokenexception error. This is my code:
starus_fail.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dialog = ProgressDialog.show(getApplicationContext(),
"Please Wait... ", "Loading... ");
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
somefunction();
if (dialog != null) {
dialog.dismiss();
}
}
}, 1000);
}
});
Upvotes: 0
Views: 212
Reputation: 6792
Just to have an answer for the above, ProgressDialog uses a context of the Activity calling it.
So just pass
YourActivity.this
Instead of
getApplicationContext
See www.doubleencore.in/2013/06/context/ for more detailed understanding of contextual
Upvotes: 0
Reputation: 541
Do not use application context for create dialog. Instead use Activity context. Here you can get it from View.getContext(). so replace your create of PorgressDialog to this:
dialog = ProgressDialog.show(arg0.getContext(), "Please Wait... ", "Loading... ");
Upvotes: 1