Removing ClickHandler from Button?

963 views
Skip to first unread message

Milan Cvejic

unread,
Jul 4, 2011, 7:05:49 PM7/4/11
to Google Web Toolkit
Hi,
I am trying to find a way how to remove ClickHandler from Button,
there is no any method related to this. I see that we can remove
ClickListener with removeClickListener(), but there is no way to
remove ClickHandler.

I am using following code:

Button b = new Button("test");
b.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("test");
}
});

Is there any way to remove ClickHandler?

Thanks.

Rob Coops

unread,
Jul 4, 2011, 7:14:04 PM7/4/11
to google-we...@googlegroups.com
removeClickListner() is deprecated if I am not mistaken...

Anyway the big question is why remove the clickHandler from your button in the first place a button that can not be clicked is nothing more then a label with a border...
I would suggest disabling the button or simply have the clickHandler return instead of doing anything... in both cases for the user nothing will happen once they click the button.

just my 2 cents.

Regards,

Rob


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Milan Cvejic

unread,
Jul 4, 2011, 8:03:37 PM7/4/11
to Google Web Toolkit
Yes, removeClickListener() is depricated, and that is why I am trying
to find solution on how to remove ClickHandler.

Just to explain my use case. I am same view with editor framework, so
I need different functionality when button is clicked.
Since button is initialized only once (in view that is constructed
only once) i need to handle event differently.

So now on start of activity i attach Listener and on stop I remove
Listener, and everything works as it should. If I don't remove
Listener, I am having
situation that event is triggered twice or more times.

I can change code to create new instance of View each time, but that
is more cpu intensive than adding and removing listeners.

Cheers.


On Jul 5, 1:14 am, Rob Coops <rco...@gmail.com> wrote:
> removeClickListner() is deprecated if I am not mistaken...
>
> Anyway the big question is why remove the clickHandler from your button in
> the first place a button that can not be clicked is nothing more then a
> label with a border...
> I would suggest disabling the button or simply have the clickHandler return
> instead of doing anything... in both cases for the user nothing will happen
> once they click the button.
>
> just my 2 cents.
>
> Regards,
>
> Rob
>

Mauro Bertapelle

unread,
Jul 5, 2011, 2:55:39 AM7/5/11
to Google Web Toolkit
use the HandlerRegistration returned from Button.addClickHandler

Milan Cvejic

unread,
Jul 5, 2011, 3:56:06 PM7/5/11
to Google Web Toolkit
Thanks for answer.

Cheers

On Jul 5, 8:55 am, Mauro Bertapelle <mauro.bertape...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages