Android alert dialog query
I have been working on android application and I have got stuck at a point.
I have a method whic开发者_StackOverflow社区h shows a progress dialog to the user. Then after the code has run I am showing an alert dialog.
Here I have got stuck. The progress dialog is not showing when method calls.
Code:
progressDialog = ProgressDialog.show(NameOfYourActivity.this, "", "Loading. Please wait...", true);
Thanks
put a title or try with null
progressDialog = ProgressDialog.show(NameOfYourActivity.this, "Title", "Loading. Please wait...", true);
progressDialog = ProgressDialog.show(NameOfYourActivity.this, null, "Loading. Please wait...", true);
What does the UI thread do next? Dialog showing code won't work until the UI thread returns from the current method - as in all GUI systems, window drawing logic is queued and invoked from the message loop. So if you show the dialog and then immediately start the loading, the dialog won't get a chance to show.
For one thing, doing lengthy loading in the UI thread is universally considered a bad design. I'd advise you to move the loading into either Thread or AsyncTask. But as a first step, you can insert a trip to the message loop between show() and the rest, like this:
ProgressDialog.show()
new Handler().post(new Runnable(){
public void run()
{
//Rest of the method
}});
this line just create the dialog object
progressDialog = ProgressDialog.show(NameOfYourActivity.this, "", "Loading. Please wait...", true);
after this call
progressDialog.show();
精彩评论