Android Question [Solved] - Custom Views - Event Parameters

mangojack

Expert
Licensed User
Longtime User
Adding a simple _Click Event to a Custom View (without parameters) results in a warning "," expected then an error when compiling.

Normaly a _Click event does not have any parameters , and I do not need to pass any.

An Earlier tutorial for Custom Views shows you did not need to pass any . Custom Views with Designer Support

B4X:
'Events declaration
#Event: DoubleClick
#Event: SingleClick

But then an updated tutorial ( B4J ) shows Event declaration as such ..
B4X:
#Event: ExampleEvent (Value As Int)

The B4A Manual simply states ...
If the event routine has parameters these must also be declared.
#Event: ExampleEvent (Value As Int)


I can just pass a Boolean in the signature and all is good and problem solved, But I just need clarification
that Custom View Events by default must have at least a single parameter , or I am doing something wrong.

Regards and Thanks
 
Solution
Adding a simple _Click Event to a Custom View (without parameters) results in a warning "," expected then an error when compiling.
You should show us your code.
So we can see what you are doing.
Which event in the CustomView is supposed to generate the Click event.

As an example, this code works:
B4X:
Private Sub lblX_Click
    et.Text = ""
    If SubExists(mCallback, mEventName & "_Click") Then
        CallSub(mCallback, mEventName & "_Click")
    End If
End Sub

I am afraid that you tried with CallSub2 instead of CallSub.

mangojack

Expert
Licensed User
Longtime User
Just to clarify , I am attempting to add a second Event to the Custom View Places Autocomplete

The view already had an event in place which did have parameters..
B4X:
#Event: ItemClick (Place As PlaceData)

#Event: Click   'will not accept this event without parameter
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Adding a simple _Click Event to a Custom View (without parameters) results in a warning "," expected then an error when compiling.
You should show us your code.
So we can see what you are doing.
Which event in the CustomView is supposed to generate the Click event.

As an example, this code works:
B4X:
Private Sub lblX_Click
    et.Text = ""
    If SubExists(mCallback, mEventName & "_Click") Then
        CallSub(mCallback, mEventName & "_Click")
    End If
End Sub

I am afraid that you tried with CallSub2 instead of CallSub.
 
Upvote 1
Solution

mangojack

Expert
Licensed User
Longtime User
I am afraid that you tried with CallSub2 instead of CallSub.


Thank you Klaus ... Thats exactly the case . I was using CallSub2 , which expected a 3rd Parameter - Argument As Object.

Capture.PNG


I Have altered my code , calling CallSub () solves the issue.

Could not see the forrest for the trees ...
 
Upvote 0
Top