How do I hide the back button of a form?

4,707 views
Skip to first unread message

david.al...@gmail.com

unread,
Sep 16, 2014, 4:46:27 PM9/16/14
to codenameone...@googlegroups.com
IDE: Eclipse
Win 8
Simulator

Disclaimer: I first tried to skim through the search results, but didn't find anything of use so I'm sorry if this question has been answered before or is easy (I'm new to Codename1)

I'm using the UI builder and have a pretty simple navigation structure, a main form which can lead to 3-4 different forms at the click/tap of a button.

If I simply use showForm("DifficultySelectForm", null); in the action event handler of the button, the form does display, but i get the back button automatically appear in the title bar next to the title. I do want this in some of the forms, but I don't want it in one of the forms, that one is supposed to have special exit conditions so I want to hide the back button for that form. How can i accomplish that?

btw: how can I, in the StateMachine class (where most code is encouraged to be written), access my defined forms? showForm does return a Form object in code, but I assume it also triggers the show in the UI.

Thanks in advance!

Regards,
DAV

Joshua Aroke

unread,
Sep 16, 2014, 7:02:25 PM9/16/14
to codenameone...@googlegroups.com, david.al...@gmail.com
Try this on your post or before form show method
 
@Override
    protected void postDifficultySelectForm(Form f) {

        f.removeCommand(f.getBackCommand());

    }

Shai Almog

unread,
Sep 17, 2014, 2:06:49 AM9/17/14
to codenameone...@googlegroups.com, david.al...@gmail.com
Override:
    protected boolean allowBackTo(String formName)

To indicate whether back should be generated at all.
Also check out the JavaDocs of UIBuilder for isSameBackDestination & setBackDestination.

david.al...@gmail.com

unread,
Sep 17, 2014, 4:55:12 PM9/17/14
to codenameone...@googlegroups.com, david.al...@gmail.com
Hi Joshua,

This doesn't work, but thanks for giving is a shot.

Regards,
DAV

david.al...@gmail.com

unread,
Sep 17, 2014, 5:06:25 PM9/17/14
to codenameone...@googlegroups.com, david.al...@gmail.com
Hi,

Tried to override allowBackTo(String formName), but the problem there is that more forms' back action go to my first form. And as I discovered, when pressing back from any form going back to the first form, the name parameter is my "FirstForm". This means that I can't filter on the form name param to return false from that method, that would disable the back action on any form  that goes back to my "FirstForm"

I also looked at what you suggested, isSameBackDestination and setBackDestination, but doesn't seem to help in my case, or your answer was too cryptic, or i'm just not getting how this could help.

What I have is a "FirstForm" with 3 buttons that navigate to 3 different forms. All of those 3 forms back action should be my "FirstForm", but i want only one of them to not be able to back to anything. How can I do this?

Thanks in advance

Regards,
DAV

Shai Almog

unread,
Sep 18, 2014, 1:02:20 AM9/18/14
to codenameone...@googlegroups.com, david.al...@gmail.com
Hi,
OK that last sentence was what I needed to understand what you are trying to accomplish.
Just override:
    protected void setBackCommand(Form f, Command backCommand)

For the 2 forms just invoke super. For the last form just do nothing.
f.getName() should return the name of the form so you can test if that's the 3rd form.

david.al...@gmail.com

unread,
Sep 23, 2014, 11:24:04 AM9/23/14
to codenameone...@googlegroups.com, david.al...@gmail.com
Yes! That did it, thanks!

joanne....@gmail.com

unread,
Nov 18, 2016, 10:32:07 PM11/18/16
to CodenameOne Discussions, david.al...@gmail.com
How is this done?
I mean, where do I put it?

Thanks!

Shai Almog

unread,
Nov 19, 2016, 12:52:30 AM11/19/16
to CodenameOne Discussions, david.al...@gmail.com, joanne....@gmail.com
This is a thread from 2014 and a lot of things have changed since then. I suggest opening a new question where you describe your current issue.
Reply all
Reply to author
Forward
0 new messages