Add event handler to designer generated views

Status
Not open for further replies.

GuerillaProgrammer

Member
Licensed User
Longtime User
Is there a way to add a single event handler to all the views of a certain type when they are generated with the designer.

I know the admonition not to initialize a designer generated view, but is there a way to add another delegate on top of the default?

I'd rather not add a call to a secondary user-defined sub into every OnClick event of every view i want to process, and I would prefer to use the designer instead of creating all the views in code.

Also, may I please have an explanation of how the event delegation is handled under the covers when the designer initializes the view? For example, in c# one may assign as many event handlers(delegates) as wished to any control and to any of its events.

It appears to me that, in B4A, more than one event handler can be assigned to a view, but only one per event type. Is that correct?

Thanks for everybody's time.
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
You can replace the event name by your own... Then if multiple similar views are used, you can copy/paste them and the custom event name will be kept.
Note: different views have different events... But many have the same basic events....
You can for example create 3 buttons (button1, button2 and button3) and set the event handler to be just btn...
This way every button n click will fire the same event (btn_click)
 

GuerillaProgrammer

Member
Licensed User
Longtime User
You can replace the event name by your own... Then if multiple similar views are used, you can copy/paste them and the custom event name will be kept.
Note: different views have different events... But many have the same basic events....
You can for example create 3 buttons (button1, button2 and button3) and set the event handler to be just btn...
This way every button n click will fire the same event (btn_click)

Thank you. I believe you are referencing the 'Event Name' property in the properties of the view in the designer.

If that's correct it would mean, however, that I can no longer have a separate OnClick event handler for any of those views for which I do this. Is that a correct conclusion?

What I would like to do is to have more than one event handler assigned to a specific event, i.e. a click event would trigger the designer-assigned OnClick handler, but would also run another user-defined Sub which checked the text string of an EditText for permissible characters, or a spinner selection for a specific value. It doesn't matter in which order they fire.
 

Cableguy

Expert
Licensed User
Longtime User
Yes, only one event handler is possible, however, using the sender keywords and the tag property you can act differently for different views, even if they target the same event
 

GuerillaProgrammer

Member
Licensed User
Longtime User
Yes, only one event handler is possible, however, using the sender keywords and the tag property you can act differently for different views, even if they target the same event


Thank you for clarifying this. It saves me a lot of time figuring it out.

Just as an aside, if I do it that way it means turning the paradigm inside out. Instead of calling the user-defined sub from multiple view event handlers, I will be calling multiple view event handlers from a common sub. (sigh)

Have a great day, and thanks again.:)
 
Status
Not open for further replies.
Top