在 HttpRequest 期间显示 ProgressDialog

发布于 2024-10-21 16:54:55 字数 1183 浏览 1 评论 0原文

可能的重复:
如何在启动活动之前显示进度对话框安卓?

这是我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯然#的苍凉 2024-10-28 16:54:55

您希望在后台执行操作时使用 AsyncTask 显示 ProgressDialog

尝试这个答案,其中包含完整的代码示例。

使用您的代码,您实际上是在系统有机会绘制对话框之前显示并关闭对话框。

You want to use an AsyncTask to display a ProgressDialog 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文