确认对话框中的Andr​​oid(andengine) [英] Confirmation Dialog in Android (andengine)

查看:170
本文介绍了确认对话框中的Andr​​oid(andengine)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Android应用程序,我试图找出如何,弹出确认窗口,以显示与确认和取消按钮,当按钮为pressed。

I am working on an android app and am trying to figure out how to get a popup confirmation window to display with confirm and cancel buttons when a button is pressed.

下面是警报的创建。

final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(activity);
    alertBuilder.setTitle("Your Title");
    alertBuilder.setMessage("Your Messages");
    alertBuilder.setPositiveButton("Confirm", new OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Do something with value!

        }
    });

    alertBuilder.setNegativeButton("Cancel", new OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Canceled.
        }
    });

下面是显示的呼叫。

 Sprite p2 = new Sprite(goldMult, 25, 450, WIDTH, HEIGHT,
            resourceManager.spriteRegion, vbom) {

        /**
         * @see org.andengine.entity.shape.Shape#onAreaTouched(org.andengine.input.touch.TouchEvent, float, float)
         */
        @Override
        public boolean onAreaTouched(final TouchEvent sceneTouchEvent, final float touchAreaLocalX,
                final float touchAreaLocalY) {

            AlertDialog alert = alertBuilder.create(); 
            alert.show();

我得到这个异​​常:
了java.lang.RuntimeException:无法内螺纹尚未调用创建活套处理prepare()

我看到了一个类似的问题<一后href=\"http://stackoverflow.com/questions/17168881/how-to-create-alert-dialog-with-andengine\">here

I saw a post with a similar issue here

不过,我如何用我的onAreaClicked事件实现这个困惑。
感谢先进的任何帮助。

However I am confused on how to implement this with my onAreaClicked event. Thanks for any help in advanced

推荐答案

我在一个新的线程包装警报想出答案

I figured out the answer by wrapping the Alert in a new thread

activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {

                    AlertDialog.Builder alert = new AlertDialog.Builder(activity);
                    alert.setTitle("");
                    alert.setMessage("");
                    alert.setPositiveButton("Buy", new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {

                        }
                    });
                    alert.setNegativeButton("Cancel", new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {

                        }
                    });

                    alert.show();
                }
            });

这篇关于确认对话框中的Andr​​oid(andengine)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆