2

What is the best practice with the new GUI Builder, to simply navigate from "form A" to another "form B" by clicking a button in "form A", with use of the action events?

If I create Form B inside Form A like this

public void oncreateAccountActionEvent(com.codename1.ui.events.ActionEvent ev) {
        new FormB().show();
    }

Then I am obviously not able to modify Form B from inside the main class (start, stop, destroy methods) before I do new FormB().show(). In this case new FormA().show(); is located in the start-method of the main class.

I want to be able to specfiy e.g. a back-button to Form B to navigate back to Form A, but I want to add this inside the start-method of the Main class.

Thanks!

Edit:

I have the Main-class (with start(), stop(), destroy()-methods), in this class I do new FormA().show().

But inside the class of FormA I have the oncreateAccountActionEvent-method (and button) which shows FormB by new FormB().show().

However I want to be able to specify formB.setBackCommand() (into the toolbar of FormB inside the main-class.

So to say I want to specify both forms in the main class with new FormA/B() - then modify the forms like adding buttons to the toolbar - and then tell FormA that FormB should be used inside the action event method.

socona
  • 432
  • 3
  • 13

2 Answers2

3

Use showBack() method to go back to FormA from FormB as shown in the code below. You can just keep a reference to the previous/next form instances.

FormA formA = new FormA();
FormB formB = new FormB();

public void oncreateAccountActionEvent(com.codename1.ui.events.ActionEvent ev) {
   formB.show();
}

public void showFormA(){
   formA.showBack();
}
Shai Almog
  • 51,749
  • 5
  • 35
  • 65
tizbn
  • 1,907
  • 11
  • 16
0

I came to an obvious solution to my problem by simply overriding the oncreateAccountActionEvent-method in the Main-class and still being able to create and modify formB before:

Form formB= new FormB();
// Modifying formB
formB.setBackCommand(backCommand);
...

//Create formA and show the modified formB on button click
FormA formA= new FormA() {
   @Override
   public void oncreateAccountActionEvent(ActionEvent ev) {
        //Navigate to FormB
        formB.show();
   };
};

And for navigating back from formB to formA I found this solution, to keep a reference of the previous form by implementing the show()-method of the class of formB:

private Form previous;
...

public void show() {
        previous = Display.getInstance().getCurrent();
        super.show();
}
...
//go to the form before
public void goBack(){
        previous.showBack();
}

Maybe this helps someone else, too.

socona
  • 432
  • 3
  • 13