【问题标题】:Android: Cannot dismiss progressdialogAndroid:无法关闭进度对话框
【发布时间】:2011-05-09 18:44:23
【问题描述】:

我试图关闭一个进度对话框,但由于某种原因它似乎不起作用。任何建议为什么会这样? 进度对话框在按钮单击时初始化并显示对话框。 syncbutton 方法调用一个发送空消息的线程

谢谢

mHandler.sendEmptyMessage(0);//来自线程

按钮点击代码

public void onClick(View v) {
                    pd = new ProgressDialog(Screen.this);
                    pd.setCancelable(true);
                    ProgressDialog.show(Screen.this, "Sync", "Sync in progress",true,false);
                    SyncButton();

                }
            });

应该关闭进度条的消息处理程序代码

mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    Log.d("Handler","handler");
                    if (Screen==true){
                        if (pd !=null)
                        { 
                            pd.cancel();
                            pd.dismiss();
                            Log.d("HANDLER", "called dismiss");
                        } 


                    }
                }

            };

PS:我确实尝试过使用 asynctask,但遇到了问题。这就是为什么采取这种方法。我已经发布了这个问题here

【问题讨论】:

    标签: android multithreading progressdialog


    【解决方案1】:

    看起来您正在这里创建一个进度对话框:

    pd = new ProgressDialog(Screen.this);
    pd.setCancelable(true);
    

    那个没有显示。您创建并显示另一个:

    ProgressDialog.show(Screen.this, "Sync", "Sync in progress",true,false);
    

    删除前两行,并将另一行更改为:

    pd = ProgressDialog.show(Screen.this, "Sync", "Sync in progress",true,false);
    

    【讨论】:

      【解决方案2】:

      您不是在显示您创建的 pd,而是在显示一个新的。

      构建 pd

      pd.setTitle("Sync");
      pd.setMessage("Sync in progress");
      

      然后使用

      pd.show();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-08
        • 1970-01-01
        • 1970-01-01
        • 2016-07-19
        相关资源
        最近更新 更多