ProgressDialog 未显示在活动中
我正在尝试在我的应用程序中包含 ProgressDialog。但它没有出现。
这是我使用 ProgressDialog 的代码片段:
public class abcActivity extends Activity {
public boolean onOptionsItemSelected(MenuItem item) {
case XYZ:
ProgressDialog dialog = ProgressDialog.show(abcActivity.this, "", "Please wait for few seconds...", true);
callSomeFunction();
dialog.dismiss();
showToast(getString(R.string.SomeString));
break;
}
}
有谁知道为什么对话框没有显示?有什么线索吗?
I am trying to include a ProgressDialog in my application. But it is not showing up.
Here's the code snippet where i use the ProgressDialog:
public class abcActivity extends Activity {
public boolean onOptionsItemSelected(MenuItem item) {
case XYZ:
ProgressDialog dialog = ProgressDialog.show(abcActivity.this, "", "Please wait for few seconds...", true);
callSomeFunction();
dialog.dismiss();
showToast(getString(R.string.SomeString));
break;
}
}
Does anyone know why the dialog is not showing up? Any clues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为您的代码在某种意义上是错误的,因为您在 UI 线程中完成了所有操作。您必须将 callsomefunction() 放入后台线程。
还有
I think your code is wrong in a sense that you do all in the UI thread. You have to put callsomefunction() into a background thread.
And as well
我认为问题出在您的开关状态上,请验证它。
这是在 android 中显示对话框的另一种方法,试试这个。
i think issue is in your switch condition pls verify it.
here is another method to display dialog in android try this.
确保您通过调试或添加日志来调用此代码。该代码对我来说似乎是正确的。
另外,如果您想在后台执行某些操作并在执行时显示进度对话框,请使用带有 ProgressDialog 边界的 AsyncTask,例如 此处。
Ensure you have this code called by debugging or adding a log. The code seems right to me.
Also, if you want to perform some operations in background and show a progress dialog while the performing, please use AsyncTask with ProgressDialog bounded, like here.
ProgressDialog 在 Android O 中已弃用,现在使用 ProgressBar。
ProgressDialog is deprecated in Android O , Use ProgressBar now.