Change MenuBar options when Tab selection changes

41 views
Skip to first unread message

Godwin

unread,
Sep 18, 2015, 5:04:38 AM9/18/15
to CodenameOne Discussions
I have implemented Tab selection listener to change the menu options whenever tab is selected but the problem is that once a tab is re-selected, the listener doesn't call the action for it again.
This is my code:

final Tabs tab = findTabs1(f);

        tab
.addSelectionListener(new SelectionListener() {
           
public void selectionChanged(int oldSelected, int newSelected) {
               
               
System.out.println("selected :: " + newSelected);
               
if ((newSelected == 0) || (newSelected == 2)) {
                    f
.getMenuBar().removeAll();
                    f
.getMenuBar().addCommand(sendSMS);
                    f
.getMenuBar().addCommand(advSearch);
                    f
.getMenuBar().addCommand(myProfile);
                    f
.getMenuBar().addCommand(abtUS);
                    f
.getMenuBar().revalidate();
               
} else if (newSelected == 1) {
                    f
.getMenuBar().removeAll();
                    f
.getMenuBar().addCommand(sendSMS);
                    f
.getMenuBar().addCommand(advSearch);
                    f
.getMenuBar().addCommand(myProfile);
                    f
.getMenuBar().addCommand(newPost);
                    f
.getMenuBar().addCommand(abtUS);
                    f
.getMenuBar().revalidate();
               
}
           
}
       
});

        f
.getMenuBar().addCommand(sendSMS);
        f
.getMenuBar().addCommand(advSearch);
        f
.getMenuBar().addCommand(myProfile);
        f
.getMenuBar().addCommand(abtUS);
        f
.getMenuBar().revalidate();

Condition works at first but when the tab is selected again, the options does not change. How can I get it to work?

If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans
Desktop OS : Windows
Simulator : Yes
Device : Not tested

Shai Almog

unread,
Sep 19, 2015, 12:18:40 AM9/19/15
to CodenameOne Discussions
If the currently selected tab is clicked again you won't be an event since no selection occurred.
You can bind your own listeners to the tab buttons if you wish.

Agada Godwin

unread,
Sep 19, 2015, 4:15:01 AM9/19/15
to codenameone...@googlegroups.com

What I mean is that if I select, say, tab 1, then select tab 2 and then select tab 1 again, the action on tab 1 is not called the second time.

On 19 Sep 2015 05:18, "Shai Almog" <shai....@gmail.com> wrote:
If the currently selected tab is clicked again you won't be an event since no selection occurred.
You can bind your own listeners to the tab buttons if you wish.

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/XE7WVZwd81c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/f9f03a8d-3c05-4f5b-bf28-897da6f3449f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shai Almog

unread,
Sep 19, 2015, 11:47:11 PM9/19/15
to CodenameOne Discussions
I'm not aware of such an issue, maybe Chen has an idea here.

Godwin

unread,
Sep 22, 2015, 9:46:45 AM9/22/15
to CodenameOne Discussions
Just figured out the problem. 
f.getMenuBar().removeAll();
does not work. I thought the listener isn't called. So I had to use
f.removeAllCommands();

to remove the commands and re-add the ones I need.
Reply all
Reply to author
Forward
0 new messages