在 HttpRequest 期间显示 ProgressDialog
可能的重复:
如何在启动活动之前显示进度对话框安卓?
这是我的 itemDetails extends Activity
类,onOkClick
是方法。但是当我按下“确定”按钮时,即调用该方法时,不会显示 ProgressDialog
。但Toast 消息显示正确。
我尝试在 ProgressDialog.show()
方法的 Context 参数中使用 getApplicationContext()
,但它不起作用。抱歉问这个幼稚的问题。
public void onOkClick(View v){
ProgressDialog pleaseWait = ProgressDialog.show(itemDetails.this, "Uploading..", "Please wait for a while...", true);
//...........
HttpData httpData = HttpRequest.post("http://www.abc.com/accessServer.php", "");
//...........
pleaseWaitGallery.dismiss();
if(HttpPostTesting.storestring.contains("successful")){
Toast.makeText(getApplicationContext(), "Uploading Complete", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(getApplicationContext(), "Uploading Failed!", Toast.LENGTH_LONG).show();
}
}
Possible Duplicate:
How to display progress dialog before starting an activity in Android?
this is my itemDetails extends Activity
class and onOkClick
is the method. But when I press the ok button i.e call the method no ProgressDialog
shows up. But the Toast messages show correctly.
I tried using getApplicationContext()
in the Context parameter of the ProgressDialog.show()
method, but it is not working. Sorry for this naive question.
public void onOkClick(View v){
ProgressDialog pleaseWait = ProgressDialog.show(itemDetails.this, "Uploading..", "Please wait for a while...", true);
//...........
HttpData httpData = HttpRequest.post("http://www.abc.com/accessServer.php", "");
//...........
pleaseWaitGallery.dismiss();
if(HttpPostTesting.storestring.contains("successful")){
Toast.makeText(getApplicationContext(), "Uploading Complete", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(getApplicationContext(), "Uploading Failed!", Toast.LENGTH_LONG).show();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您希望在后台执行操作时使用
AsyncTask
显示ProgressDialog
。尝试这个答案,其中包含完整的代码示例。
使用您的代码,您实际上是在系统有机会绘制对话框之前显示并关闭对话框。
You want to use an
AsyncTask
to display aProgressDialog
while doing operations in the background.Try this answer, which contains a full code sample.
With your code, you are actually showing and dismissing the dialog before the system has a chance to draw it.