如何在Cocos2dxActivity中显示自定义android对话框(带有自定义布局)? 我尝试通过JNI调用一个方法,在其中我创建了一个Dialog,设置了它的布局并显示它。
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()
答案 0 :(得分: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();
}
});
}