Android Question Passing Object from event to a Sub

Robert S

New Member
Licensed User
Longtime User
Hi,
Just started writing code again after a break of 8 or more years and I have have not been able to work out how to pass a reference to a button from its button click event in the main module to a sub in the BX module.

The tag value of the button contains data I want to use. I can cycle through the objects on the screen using btn = pnl.getview(i) and access the tag value that way, but how to I know which of the buttons is the one that was clicked as I cant find a way to pass the object explicitly from the click event or to access the button name to compare it to the name derived from the click event.

Thanks
Robert
 

Daestrum

Expert
Licensed User
Longtime User
think you need to use Sender
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Hi,
Just started writing code again after a break of 8 or more years and I have have not been able to work out how to pass a reference to a button from its button click event in the main module to a sub in the BX module.

The tag value of the button contains data I want to use. I can cycle through the objects on the screen using btn = pnl.getview(i) and access the tag value that way, but how to I know which of the buttons is the one that was clicked as I cant find a way to pass the object explicitly from the click event or to access the button name to compare it to the name derived from the click event.

Thanks
Robert
Post an example project so we can work on what you have done up to now.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Hi,
Just started writing code again after a break of 8 or more years and I have have not been able to work out how to pass a reference to a button from its button click event in the main module to a sub in the BX module.

The tag value of the button contains data I want to use. I can cycle through the objects on the screen using btn = pnl.getview(i) and access the tag value that way, but how to I know which of the buttons is the one that was clicked as I cant find a way to pass the object explicitly from the click event or to access the button name to compare it to the name derived from the click event.

Thanks
Robert
Private Sub btnMenu_Click

Dim vBtn As B4XView = Sender
Dim oButtonTag As Object = vBtn.Tag

RBS
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Thanks, I reckon that should do it. I had not found the Sender construct.

Method_636.png
Sender As Object​

Returns the object that raised the event.
Only valid while inside the event sub.
Example:
Sub Button_Click
Dim b As Button
b = Sender
b.Text = "I've been clicked"
End Sub
 
Upvote 0
Top