Skip to content Skip to sidebar Skip to footer

Andengine Ask Questions With Toast?

I wonder if there is any native support for andengine or ADK to ask question-toasts? For example if I press the back button, I want some box to popup asking if I really want to qui

Solution 1:

Better to use alert dialog use this code, hope work same like that

@OverridepublicbooleanonKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stubswitch(keyCode)
    {
    case KeyEvent.KEYCODE_BACK:
        AlertDialog.Builderab=newAlertDialog.Builder(AlertDialogExampleActivity.this);
        ab.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
        .setNegativeButton("No", dialogClickListener).show();
        break;
    }

    returnsuper.onKeyDown(keyCode, event);
}

DialogInterface.OnClickListenerdialogClickListener=newDialogInterface.OnClickListener() {
    @OverridepublicvoidonClick(DialogInterface dialog, int which) {
        switch (which){
        case DialogInterface.BUTTON_POSITIVE:
            //Yes button clickedbreak;

        case DialogInterface.BUTTON_NEGATIVE:
            //No button clickedbreak;
        }
    }
}

Solution 2:

You found your solution that is good but for the above answer you have to use AndEngine functionality. If you are working with AndEngine then you have to develop all the things with AndEngine power.

So for your solution you have to create one child scene which popup when user press device back button like in the following code snippet.

classDialogBoxextendsScene{
    DialogBox(...){
    }
    // you have to include all the functionality that your dialog box should contain
}

You have to set above dialog box as child of your main scene like in the following manner on the back event of user.

mScene.setAsChildScene(newDialogBox(...));

I prefer this way if I am developing a game.

Post a Comment for "Andengine Ask Questions With Toast?"