gpt4 book ai didi

android - 在 opengl 线程中启动自己的对话框的最佳方式

转载 作者:行者123 更新时间:2023-11-29 14:08:17 24 4
gpt4 key购买 nike

从 opengl 线程启动对话的最佳方式是什么。我创建了一个小的 opengl 游戏,最后我想显示一个自定义对话框。有人举例说明如何做到这一点吗?

谢谢

最佳答案

好吧,我只是知道,在我的 Optimus LG 2x 上,使用目标 Android 2.3.3(并遵循来自 Android 网站的警报文档:http://developer.android.com/guide/topics/ui/dialogs.html)是这样的:

我已经实现了我的自定义 GLSurfaceView,它覆盖了 public boolean onTouchEvent(MotionEvent event) 方法。然后在那个方法中,当用户触摸屏幕时,我这样做:

@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN) {

AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do something
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
return true;
}
return false;

关于android - 在 opengl 线程中启动自己的对话框的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5423522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com