【问题标题】:Progress dialog not displaying进度对话框不显示
【发布时间】:2013-12-03 23:26:27
【问题描述】:

我有一个在 kitkat 之前工作的进度对话框,现在它不显示对话框。 如果我在对话框关闭之前进行调试并在后执行中停止程序,则会显示对话框,这意味着代码工作得太快而无法显示对话框,但这不是真的,在 dailog 关闭后需要很长时间显示网格视图?

另一个奇怪的事情,当它确实工作时,它显示了对话框,但圆圈没有转动或动画。

感谢收到任何cmets

        private class LoadPhoto extends AsyncTask<String, Void, MyPhoneImagesAdapter> {


        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // initialize the dialog
            String searchingString = getResources().getString(R.string.searchingString);
            String searchMsgString = getResources().getString(R.string.searchMsgString);
            m_dialog.setTitle("Searching...");
            m_dialog.setMessage("Please wait while loading client photos...");
            m_dialog.setIndeterminate(true);
            m_dialog.setCancelable(true);
            m_dialog.show();
        }



        @Override
        protected MyPhoneImagesAdapter doInBackground(String... params) {
            // TODO Auto-generated method stub
        // Execution code
            // Note we can call a method in the main class but we are running it in
            // the asynchronous thread
            getPhotos();
            return getPhotos();
        }

        @Override
        protected void onPostExecute(MyPhoneImagesAdapter result) {
            super.onPostExecute(result);
// Note we can update the UI from the post execute method only note we pass the adapter which 
// we created in the do in background
            GridView grid = (GridView) getView().findViewById(R.id.photoGrid);
              grid.setAdapter(result);
               // See: ImageAdapter.java
              grid.setOnItemClickListener(new OnItemClickListener() {
                  public void onItemClick(AdapterView<?> parent, View v,
                          int position, long id) {
                      String tst = "Pick";
                      String sel = path+"/"+clientPhotos[position];
                      listener.onImageSelected(sel);
                      }
              });
            m_dialog.dismiss();
        }

【问题讨论】:

  • 进度对话框在哪里初始化?
  • 请确保您的 OnPreExecute 正在被调用,您可以通过敬酒来验证这一点

标签: android progressdialog


【解决方案1】:

尝试在 LoadPhoto 类中初始化 ProgressDialog

LoadPhoto 中声明ProgressDialog mProgressDialog;

并使用ProgressDialogshow()作为静态方法,

mProgressDialog = ProgressDialog.show(MainActivity.this, "Searching...", "Please wait while loading client photos...", true, true);

【讨论】:

  • 您好,感谢您的回复,我已经尝试过了,现在它会显示对话框,但不会关闭它。
  • 我认为可能有解雇(上下文)但没有
【解决方案2】:

出现这种情况的原因是处理器没有时间更新 UI,因此您必须在循环中手动执行此操作。

我不是 android 开发人员,但在 java 中,以前我通常会使用 repaint(); 函数。

在 c# 中,这些简单的函数有助于更新控件,

textbox1.Invalidate();
textbox1.Update();
textbox1.Refresh();

我相信java可能有类似的功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多