Android - Game Thread and Dialogs

风格不统一 提交于 2019-12-11 08:27:01

问题


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.

Thanks!


回答1:


you can pass the context from parent activity

for example

showLongMessage(myclass.this, returnMsg);

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();
}


来源:https://stackoverflow.com/questions/9170504/android-game-thread-and-dialogs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!