TabLayoutPanel SelectionHandler invoked multiple times

123 views
Skip to first unread message

ALB-PSP-DV1

unread,
Dec 27, 2011, 7:47:18 AM12/27/11
to Google Web Toolkit, rcle...@gmail.com
Hi,

I have a TabLayoutPanel with 3 tabs. I have added a selection handler
to it to change the color of the selected/unselected tabs.

However the selectionHandler seems to be invoked 3 times instead of
once when I select a tab.

i.e. SelectionHandler invocation = Total number of tabs in
TabLayoutPanel


@UiField
TabLayoutPanel fareDisplayPanel;

fareDisplayPanel.addSelectionHandler(new SelectionHandler<Integer>() {
@Override
public void onSelection(final SelectionEvent<Integer> event)
{
---------- code for styling selected/unselected
tabs----------
}
});

Can someone please point out the mistake that I'm doing. Thanks in
advance.

Patrick Tucker

unread,
Dec 27, 2011, 10:56:03 PM12/27/11
to Google Web Toolkit

Where are you adding the SelectionHandler?

ALB-PSP-DV1

unread,
Dec 28, 2011, 1:08:01 AM12/28/11
to Google Web Toolkit
I'm adding the selection handler to the TabLayoutPanel.

fareDisplayPanel.addSelectionHandler(new SelectionHandler<Integer>()
{ }


On Dec 28, 8:56 am, Patrick Tucker <tucker...@gmail.com> wrote:
> Where are you adding theSelectionHandler?
>
> On Dec 27, 7:47 am, ALB-PSP-DV1 <albpsp...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I have aTabLayoutPanel with 3 tabs. I have added a selection handler
> > to it to change the color of the selected/unselected tabs.
>
> > However theselectionHandlerseems to beinvoked3timesinstead of
> > once when I select a tab.
>
> > i.e.SelectionHandlerinvocation = Total number of tabs in
> >TabLayoutPanel
>
> > @UiField
> >TabLayoutPanelfareDisplayPanel;
>
> > fareDisplayPanel.addSelectionHandler(newSelectionHandler<Integer>() {

Patrick Tucker

unread,
Dec 28, 2011, 9:25:55 PM12/28/11
to Google Web Toolkit
That Is how you added the handler, I'm wondering where. If you are
adding it in the constructor, onLoad(), ...

If you are adding it in onLoad or some function that is called
multiple time, that will explain why it is firing multiple times. Add
a print statement before the add and check the output.

ALB-PSP-DV1

unread,
Dec 29, 2011, 6:07:28 AM12/29/11
to Google Web Toolkit
That was exactly the problem.
I had put it inside a function which was invoked every time a tab is
created. Due to this, selection handler was getting added multiple
times.I moved it to the constructor and now it is invoked just once.
Thanks a lot for the guidance.
On Dec 29, 7:25 am, Patrick Tucker <tucker...@gmail.com> wrote:
> That Is how you added the handler, I'm wondering where.  If you are
> adding it in the constructor, onLoad(), ...
>
> If you are adding it in onLoad or some function that is calledmultipletime, that will explain why it is firingmultipletimes.  Add
> a print statement before the add and check the output.
>
> On Dec 28, 1:08 am, ALB-PSP-DV1 <albpsp...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I'm adding the selection handler to theTabLayoutPanel.
>
> > fareDisplayPanel.addSelectionHandler(newSelectionHandler<Integer>()
Reply all
Reply to author
Forward
0 new messages