Back before Back

43 views
Skip to first unread message

kta...@gmail.com

unread,
Jun 13, 2014, 1:13:34 PM6/13/14
to codenameone...@googlegroups.com
I have a bunch of forms that display data on a form using tabs, where sometimes a button inside a tab might switch over to another tab.
As a result sometimes people get confused and think since they clicked something the back button will now go to the tab they were on when they clicked the button.
So I wrote some code that makes it so when you switch a tab the back button goes back to the original tab, before going to the previous form.
And it works fine for forms that have an existing back command in their constructor (to go to a previous form).


tabs = new Tabs();
tabs.addSelectionListener(new SelectionListener() {
private Command origBackCommand;
private final Command firstTab = new Command("First Tab") {
@Override
public void actionPerformed(ActionEvent evt) {
tabs.setSelectedIndex(0);
}
};
public void selectionChanged(int oldSelected, int newSelected) {
if(oldSelected == 0) {
Log.p("Selected Other Tab");
origBackCommand = getBackCommand();
if(origBackCommand == firstTab) {
Log.p("Set back command to first tab, this should never happen.");
origBackCommand = null;
}
setBackCommand(firstTab);
setMinimizeOnBack(false);
} else if(newSelected == 0) {
Log.p("Selected First Tab");
if(origBackCommand != null) {
Log.p("Original Command Loaded");
setBackCommand(origBackCommand);
setMinimizeOnBack(false);
origBackCommand = null;
} else {
setBackCommand(null);
setMinimizeOnBack(true);
}
}
}
});

But I also have 2 forms yo land on when you launch the app, one that shows when you're logged out, and one when your logged in.
As a result neither have a back command setup when they're constructed.

So with the code above, I'd expect if you switch to a tab, than back to the first, when no existing back command was set, it would disable the back button.
However I'm having the following issues:

On the simulator with a ICS android skin the back button is never reset, and will sometimes glitch to display the first tab text.
On Android (Tested on a Nexus 7 with Android 4.4) the back button continues to show but minimizes normally.

Shai Almog

unread,
Jun 14, 2014, 1:02:10 AM6/14/14
to codenameone...@googlegroups.com, kta...@gmail.com
I'm guessing that you are getting duplicate events or some events are missing, its hard to pinpoint this though. I suggest you log the calls you get to the selection event then filter out redundant calls in your logic.
Reply all
Reply to author
Forward
0 new messages