Switching NavItems causes the event to fire twice

16 views
Skip to first unread message

hgeor...@gmail.com

unread,
Jun 6, 2013, 10:47:55 PM6/6/13
to spif...@googlegroups.com
Hi,

I have a MainNavBar with NavItems in it, and I've mimicked the code I found in one the SpiffyUI sample projects.

I've created a somewhat different event handler though:

@Override
public void itemSelected(NavItem item)
{
System.out.println("Item ID: " + item.getId());

if (item.getId().equals("abc"))
{
System.out.println("Inside abc");
}
else
{
System.out.println("Inside def");
}     
}


If I have two different NavItems with IDs "abc" and "def", when I choose "abc", in the console, I'll see: "Item ID: abc" one time. If I click the abc NavItem again, in the console I will again get "Item ID: abc", as expected.

However, once the abc NavItem is selected, if I select the def NavItem, I see in the log that "Item ID: def" gets printed twice.... This is quite an issue because I have values changing inside the event handler and I don't want things double counted. 

Has anyone else run into this issue?

Zack Grossbart

unread,
Jun 7, 2013, 8:07:58 AM6/7/13
to spif...@googlegroups.com
Hello,

I haven't run into this issue. Is it possible that you've bound the
navigation listener twice or that you have two navigation items with the
same ID? Any chance you have a sample project that we can take a look at?

Thanks,
Zack
--
You received this message because you are subscribed to the Google Groups
"Spiffy UI" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to spiffy-ui+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

hgeor...@gmail.com

unread,
Jun 7, 2013, 3:53:12 PM6/7/13
to spif...@googlegroups.com, za...@grossbart.com
Hey Zack,


Thanks for the quick reply! Here's my code: http://pastebin.com/5hyVp8r4 I apologize for it being a bit messy.

I see that: System.out.println("Item ID: " + item.getId()); gets printed twice every time I switch between NavItems


Any help would be appreciated.

Thanks!

Zack Grossbart

unread,
Jun 7, 2013, 4:55:25 PM6/7/13
to spif...@googlegroups.com
Hello,

Any chance you can share the whole project on GitHub or something like that
so I can build it and debug a little?

hgeor...@gmail.com

unread,
Jun 7, 2013, 7:29:52 PM6/7/13
to spif...@googlegroups.com, za...@grossbart.com
Unfortunately, I cannot, the project is a part of one at my company.

Is there some other way I can help maybe?

Zack Grossbart

unread,
Jun 7, 2013, 7:59:43 PM6/7/13
to spif...@googlegroups.com
It’s a little tricky to debug this without a project, but there should be a
simple work around. Each of your navigation items is required to have an
ID. You can save the last ID and compare it to the current ID when the even
fires. If the current ID matches the previous ID then it's a duplicate even
and you can skip the event handling.

Does that help?

hgeor...@gmail.com

unread,
Jun 7, 2013, 8:38:49 PM6/7/13
to spif...@googlegroups.com, za...@grossbart.com
That should work, I'll try it out. Should've thought of that myself!

Thanks!
Reply all
Reply to author
Forward
0 new messages