Reset click handler

SkinneySkinney NOMember, Beta

Hi!

I can make something happen whenever someone clicks a button, by assigning an anonomous function to it's Click event handler like this:

button.Click += (sender, args) => { something };

However, if this code runs in say, a list adapter, then one button can be add the same event mulitple times, which means the same thing happens multiple times when clicking the button... How can I reset the button before adding an event?

Posts

  • nodoidnodoid GBMember, Beta ✭✭✭

    Once the event is registered, it should only be fired once, so no need to reset or the likes.

  • SkinneySkinney NOMember, Beta

    Well that's the behaviour I'm seeing. Note that I'm using anonomous functions/lambdas here...

  • FZelleFZelle DEMember ✭✭✭

    You can't reset the button, but you can suntract the listener.

  • SkinneySkinney NOMember, Beta

    Ahh... But I'm kindof depending on closures for this to work and I think it's hard to subtract an anonomous closure? As a workaround I guess I can always use OnItemClickListener interface and set OnItemClick on the adapter to make this work...

  • FZelleFZelle DEMember ✭✭✭
    edited March 2013

    no it's not really hard to subtract an anonymous closure.

    var clickhandler = (sender, args) => { something };

    button.Click -= clickhandler:

    button.Click += clickhandler:

Sign In or Register to comment.