Android - Game Thread and Dialogs

2019-08-08 16:07发布

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条回答
对你真心纯属浪费
2楼-- · 2019-08-08 16:37

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();
}
查看更多
登录 后发表回答