0
error java.lang.RuntimeException: Can't create handler inside 
thread that has not called Looper.prepare() =(

如果我打电话-showDialog (id)工作GameActivity但如果我activity.showDialog从另一个班级打电话 - 一个错误

@Override
 protected Dialog onCreateDialog(int id) {
  switch (id) {
  case 1:
      Log.d("Dialog", "Dialog 1");
      AlertDialog.Builder alert = new AlertDialog.Builder(this);
         alert.setTitle("Help");
         alert.setMessage("Help");
         WebView wv = new WebView(this);
         wv.loadUrl("http:\\www.google.com");
         wv.setWebViewClient(new WebViewClient()
         {
             @Override
             public boolean shouldOverrideUrlLoading(WebView view, String url)
             {
                 view.loadUrl(url);
                 return true;
             }
         });
         alert.setView(wv);

         AlertDialog ALERT = alert.create();
      return ALERT;
  default:
        return null;
  } 
}

我想与任何其他班级进行对话

更新:

 new code activiti.runOnUiUpdate()

 @Override
 protected Dialog onCreateDialog(int id) {
  switch (id) {
  case 1: 
      this.runOnUiThread(new Runnable() {
      @Override
      public void run() {

      Log.d("Dialog", "Dialog 1");
      AlertDialog.Builder alert = new AlertDialog.Builder(this);
         alert.setTitle("Help");
         alert.setMessage("Help");
         WebView wv = new WebView(this);
         wv.loadUrl("http:\\www.google.com");
         wv.setWebViewClient(new WebViewClient()
         {
             @Override
             public boolean shouldOverrideUrlLoading(WebView view, String url)
             {
                 view.loadUrl(url);
                 return true;
             }
         });
         alert.setView(wv);
         AlertDialog aALERT = alert.create();

        }
      });
      return ALERT;
  default:
        return null;
  } 
}
4

1 回答 1

1

在更新线程方法中创建对话框,例如

 activity.runOnUiThread(new Runnable(){
     @Override
        public void run() {
    //code for dialog creation goes here
    }

 });

this更新活动上下文的任何内部引用,activity 您也可以dialog.show()在创建它的最后并使其在创建后显示出来。希望我有所帮助。

于 2013-09-29T11:33:38.560 回答