本文介绍了如何显示Cocos2dxActivity定制对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能显示一个Cocos2dxActivity的Android定制对话框(定制布局)?
我试着打电话通过JNI中,我创建了一个对话框,设置它的布局和显示它的方法。
How can I display a custom android dialog(with custom layout) in Cocos2dxActivity ?I tried calling a method through JNI in which I created a Dialog, set its layout and displayed it.
public void displayDialog()
{
Dialog d=new Dialog(this);
d.setContectView(R.layout.myDialog);
d.show();
}
它给了我这个错误
It gives me this error
08-21 14:34:08.045:E / AndroidRuntime(2675):了java.lang.RuntimeException:无法内螺纹已不叫尺蠖prepare创造处理器()
推荐答案
我是一个活动,你的情况我该=;关键的一点是使用runOnUiThread(新的Runnable(){公共无效的run(){}}
me is an Activity, in your case me = this; the key point is to use 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();
}
});
}
这篇关于如何显示Cocos2dxActivity定制对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!