Reputation: 518
A typical usecase for a scene2d modal dialog is to have two buttons in it, one for user action confirmation and one for cancel.
Simply clicking this cancel button results in closing (hiding) the dialog window (which is a default behaviour and basically all that is needed, since we don't want anything to happen), but then repeating the action that is supposed to show it again (ex. clicking a "Delete" button to show delete confirmation dialog) results in nothing happening (because the dialog is now hidden).
What is the proper way to enable the dialog back?
Should show() be called in the No button listener?
noButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
deleteDialog.show(stage);
};
The official scene2d code example creates a new dialog each time, but my understanding is that it's better to reuse such elements.
Upvotes: 0
Views: 316
Reputation: 195
You have your dialog in a variable I guess:
Group dialog = new Group();
You add it like this:
stage.addActor(dialog);
Listener to remove - remove method doesn't delete anything, it just removes the actor from the stage:
noButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
dialog.remove();
};
And then when you want to display it again:
stage.addActor(dialog);
Upvotes: 1