Android的 - 游戏主题和对话框对话框、主题、游戏、Android

2023-09-12 22:25:24 作者:浪漫天降

我有一款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();
}