0
\$\begingroup\$
setBtn.addListener(new ClickListener() {
    @Override

    public void clicked(InputEvent event, float x, float y) {
        final Dialog dialog = new Dialog("Settings", skin, "dialog") {
            public void result(Object obj) {
                Preferences prefs = Gdx.app.getPreferences("My Preferences");

                if (obj.equals(2))
                    muteMusic = true;
                if (obj.equals(3))
                    muteMusic = false;

                prefs.putBoolean("music", muteMusic);
                prefs.flush();


            }


        };
        dialog.text("Do you want to play music");
        dialog.button("Yes", 2); //sends "true" as the result
        dialog.button("No", 3); //sends "false" as the result
        dialog.button("Ok", false);

        dialog.show(stage);
    }

});
  • I want the ok button to be on an another row but if I do dialog.row() like with tables, it won't work, I can't add an empty row
  • I want the dialog to stay visible on the screen until the ok button is touched, only then I want to call dialog.hide()

I can't do

if (obj.equals(false))
dialog.hide(); // IDE will suggest that i create a local variable called dialog
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Any specific reason you are using dialog.button to add buttons? In my experience this should just be used for the last button of the dialog that you wish to hide the dialog with, in your case 'ok'.

Did you try something like:

TextButton txtBtn = new TextButton ("yes", skin);
TextButton txtBtn2 = new TextButton ("no", skin);

dialog.getContentTable().add(txtBtn);
dialog.getContentTable().row();
dialog.getContentTable().add(txtBtn2);

dialog.button(new TextButton("ok", skin));
\$\endgroup\$
2
  • \$\begingroup\$ so dialog.button triggers dialog.hide by default? \$\endgroup\$
    – Lynob
    Feb 7, 2017 at 13:35
  • \$\begingroup\$ As far as I know, yes \$\endgroup\$
    – Green_qaue
    Feb 7, 2017 at 13:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .