Android Question Buttons within Classes - Event_Handler not working

Gary Milne

Active Member
Licensed User
Longtime User
I have a class that contains a Button among other things. When I Initialize a new instance of the class it Initializes the Button and sets a shared Event handler. Problem is that it does not recognize any click events on the button.

If I Initialize the Button separately somewhere in the Activity (vs in the Class) then the click events are recognized.

I'm new to classes so it is probably something fundamental.

How do I make the Event_Handler visible to the Activity when it is Initialized within the class. I can work around it but it's not nearly as clean.

Any help appreciated for a B4A newbie.
 

klaus

Expert
Licensed User
Longtime User
Without seeing what exactly you have done it's impossible to give you a concrete advice.
You need to define the Click event in the Class where you can execute code.
If you need an event in the calling activity you must define one and call it from the event routine in the class.
In the class:
B4X:
Private Sub btnTest_Click
    ' code internal to the class

    If SubExists(CallbackModule, EventName & "_Click") Then
        CallSub(CallbackModule, EventName & "_Click")
    End If
End Sub

In the Activityy:
B4X:
Sub clsTest_Click

End Sub

CallbackModule, EventName are the ones you transmit in the Initialize routine for the class.
B4X:
Dim clsTest As MyClass
clsTest.Initialize(Me, "clsTest")
 
Upvote 0
Top