Android的 - 游戏主题和对话框 [英] Android - Game Thread and Dialogs

查看:184
本文介绍了Android的 - 游戏主题和对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一款Android游戏瓦特/ ViewThread和使用的onTouchEvent一个小组。什么是调用父类活动的的ShowDialog方法时,小组的的onTouchEvent被解雇,并回交流所产生的信息给底层code的最佳方法是什么?

I have a Android game w/ a ViewThread and a Panel that uses the onTouchEvent. What's the best way to call the parent Activity's 'showDialog' method when the Panel's onTouchEvent is fired and to communicate the resulting information back to the underlying code?

例如我的面板中我有以下几点:

For example in my Panel I have the following:

@Override
public boolean onTouchEvent(MotionEvent event) {
    int todo = map.click(event.getX(), event.getY());
    //If a valid square was clicked, lets popup a dialog
    if(todo == 1){
        //Activity.showDialog(1); -- Callback method or 'event' I can use to trigger?
        //map.updateWithDialogChoice(DialogResult) // How to access result from Dialog
    }
    return super.onTouchEvent(event);
}

我稍微感到困惑的正确办法漏斗信息来回这类行动的。

I'm slightly confused on the proper way to funnel information back and forth between these kind of actions.

谢谢!

推荐答案

您可以从父活动通过上下文

you can pass the context from parent activity

例如

showLongMessage(myclass.this, returnMsg);

和这是showLongMessage方法...

and this is the showLongMessage method...

public static void showLongMessage(Context ctxtform, CharSequence message) {
    new AlertDialog.Builder(ctxtform)

    .setTitle(Modules.AgentName)

    .setMessage(message)

    .setIcon(R.drawable.icon_alert)

    .setPositiveButton("OK", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton)

        {

        }
    }).show();
}

这篇关于Android的 - 游戏主题和对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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