Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeNameOne Dynamically created Form, how to "Back"

In an actionListener for a button we would like to create a Form on the fly.

Eg Something like

Button b = new Button("Clickme");
b.setActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
        Form f = new Form();
        Container c = new Container();
        ...
        f.addComponent(c);
        f.show();
    }
});

Which works fine..... but "back" button will not work

Does anyone know the correct way of implementing a dynamic form in an actionListener, or jumping to a predefined form through and action Listener?

Thanks

James

like image 283
jamesarbrown Avatar asked Sep 03 '12 20:09

jamesarbrown


1 Answers

You need to create a back command and associate it with the form:

Command back = new Command("Back") {
     public void actionPerformed(ActionEvent ev) {
         // notice that when showing a previous form it is best to use showBack() so the 
         // transition runs in reverse
         showPreviousForm();
     }
};
f.setBackCommand(back);

You can see this in the kitchen sink demo which is entirely hand coded.

like image 66
Shai Almog Avatar answered Sep 18 '22 20:09

Shai Almog