How to have the back command in InteractionDialog

39 views
Skip to first unread message

P5music

unread,
Dec 3, 2020, 4:49:09 AM12/3/20
to CodenameOne Discussions
I have a method call to set the back command in my utility dialogs, in a special class with static methods.
Now I have to use InteractionDialog instead of Dialog but I do not know how to implement  this kind of line
if (cancellable) alertDialog.setBackCommand(backCommand);
Thanks in advance

Shai Almog

unread,
Dec 3, 2020, 11:15:52 PM12/3/20
to CodenameOne Discussions
Use setBackCommand on the form. Install a command to the back action. In its actionPerformed check if you have an interaction dialog to dispose and dispose that. If not go to the previous form.

P5music

unread,
Dec 4, 2020, 4:33:52 AM12/4/20
to CodenameOne Discussions
Do you mean something like this?
public static void openMyDialog(Form form, other parameters)
{
final InteractionDialog myDialog=new InteractionDialog();
...
Command oldBackCommand=form.getBackCommand();
        Command backCommand=new Command("Back") {
            @Override
            public void actionPerformed(ActionEvent evt) {
                form.setBackCommand(oldBackCommand);
                myDialog.dispose();

            }
        };
        form.setBackCommand(backCommand);
...
}       
Is it safe?

Shai Almog

unread,
Dec 5, 2020, 2:08:31 AM12/5/20
to CodenameOne Discussions
That looks reasonable.
Reply all
Reply to author
Forward
0 new messages