0

如何在 Cocos2dxActivity 中显示自定义 android 对话框(带有自定义布局)?我尝试通过 JNI 调用一个方法,在该方法中我创建了一个对话框,设置它的布局并显示它。

public void displayDialog()
 {
    Dialog d=new Dialog(this);
    d.setContectView(R.layout.myDialog);
    d.show();
 }

它给了我这个错误

08-21 14:34:08.045: E/AndroidRuntime(2675): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

4

1 回答 1

2

我是一个活动,在你的情况下我 = 这个;关键是使用 runOnUiThread(new Runnable(){public void run(){}}

public void rateMe(String s){
    me.runOnUiThread(new Runnable() {
          public void run() {
            AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
            dialog.setTitle("Rate Me");

            dialog.setMessage("If you enjoy this game, please take a moment to rate it. Thanks for your support!");
            //tv.setWidth(240);
            dialog.setPositiveButton("Rate Now",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface arg0,
                                int arg1) {
                            mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.home.test")));
                        }

                    });

            dialog.setNegativeButton("No, thanks",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface arg0,
                                int arg1) {

                        }
                    });       
            dialog.show();    
          }
    });
}
于 2012-08-21T23:08:09.087 回答