Back button no working, can't find where to call showForm

126 views
Skip to first unread message

Dan

unread,
Nov 7, 2013, 1:16:07 PM11/7/13
to codenameone...@googlegroups.com
I can't get the back button to work. This is all done through hand coding.

Full source attached... I have this for the Command:

Command backCommand = new Command("Back") {
            public void actionPerformed(ActionEvent ev) {
                System.out.println("backCommand Fired");
                showBack();
            }
        };
       
        setBackCommand(backCommand);

When I click the back button on the emulator, it indicates that it fired. However, nothing happens.

In the forums, it seems that showForm should be used instead of show... however, I can't seem to figure out when to call it. In the examples, it's in StateMachineBase.java.

back_button_not_working.txt

Shai Almog

unread,
Nov 7, 2013, 2:03:13 PM11/7/13
to codenameone...@googlegroups.com
showBack() shows this form again with the back transition, not the previous form. You need to invoke showBack() on the previous form instance.

Dan

unread,
Nov 7, 2013, 2:35:26 PM11/7/13
to codenameone...@googlegroups.com
How do I keep track of form instance in order to do this? Maintain a list of form instances? Pass the form as a parameter when showing a new form?

Shai Almog

unread,
Nov 8, 2013, 12:12:38 AM11/8/13
to codenameone...@googlegroups.com
Either one will work.
In the GUI builder we have a state machine that creates an instance of a form dynamically based on navigation state which is a very common pattern when working with UI's in mobile.

Dan

unread,
Nov 8, 2013, 8:12:20 AM11/8/13
to codenameone...@googlegroups.com
How about this...

Adding a command to my form using the following code:

setBackCommand(new BackCommand(this));

BackCommand code:

public class BackCommand extends Command {
   
    Form previousForm;
   
    public BackCommand(Form f){
        super("Back");
        this.previousForm = f;
    }

    @Override
    public void actionPerformed(ActionEvent evt) {
        // TODO Auto-generated method stub
        //super.actionPerformed(evt);
        System.out.println("BackCommand actionPerformed");
        this.previousForm.showBack();
    }

}

It fires (I see the System output) , however, it doesn't go back.

Dan

unread,
Nov 8, 2013, 2:56:07 PM11/8/13
to codenameone...@googlegroups.com
Figured it out. I wasn't passing the right instance and wasn't affecting a local variable either.

Works now.
Reply all
Reply to author
Forward
0 new messages