Android Question Sending Events between two CustomView's

yasan_v3

Member
Licensed User
Longtime User
Hello,

i am implmenting a custom ListView. The idea is to have a CustomView that holds a ScrollView in it. The Panel of the ScrollView holds other CustomViews that represents the List Items. The CustomView that represents an Item contains some Views. One of the View is a custom label class:

B4A_Events.png

Everything is fine, the List is initialized and displayed properly with the items.
But the problem is that i can't pass the Click-Event of the Label (CustomView3) to the Custom List (CustomView1). It seems that i can only send events to Activity Modules but not to CustomViews. When i call CallSub with a CustomView-Object as the "Component" i get an error Message:

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (activities) Create, isFirst = true **
** Activity (activities) Resume **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (activities) Create, isFirst = true **
** Activity (activities) Resume **
java.lang.Exception: Sub lbl1_click signature does not match expected signature.
java.lang.Exception: Sub lbl1_click signature does not match expected signature.
java.lang.Exception: Sub lbl1_click signature does not match expected signature.
java.lang.Exception: Sub lbl1_click signature does not match expected signature.
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (activities) Create, isFirst = true **
** Activity (activities) Resume **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (activities) Create, isFirst = true **
** Activity (activities) Resume **
ylabel_label_click (B4A line: 103)
CallSub(module, event_name & "_Click")
java.lang.RuntimeException: java.lang.ClassCastException: anywheresoftware.b4a.objects.ScrollViewWrapper$MyScrollView cannot be cast to java.lang.String
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:847)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:785)
at yv3.yDiary.ylabel._label_click(ylabel.java:484)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.agraham.reflection.Reflection$2.onClick(Reflection.java:985)
at android.view.View.performClick(View.java:4240)
at android.view.View$PerformClick.run(View.java:17721)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: anywheresoftware.b4a.objects.ScrollViewWrapper$MyScrollView cannot be cast to java.lang.String
at anywheresoftware.b4a.keywords.Common.getComponentBA(Common.java:958)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:830)
... 18 more
java.lang.RuntimeException: java.lang.ClassCastException: anywheresoftware.b4a.objects.ScrollViewWrapper$MyScrollView cannot be cast to java.lang.String

Any idea how to solve the Problem?

Greetings yv3
 

yasan_v3

Member
Licensed User
Longtime User
Hello Erel,
eahm rather not sorry im working on a top secret app and the custom views would reveal what my app is all about ;) I need the list control so the user can easily manage the master data for the app. Each item must have a color plate, 2 Labels, 3 optional Icons and some custom data. I still working on the underlying "framework", i have a sandbox activity for each control and playing around.
I will take a look at the reflector object maybe its possible with it? if it doesnt work ill try to make an workaround by handling the messages in the activity module and call the according Subs of the list view from there.
 
Upvote 0

yasan_v3

Member
Licensed User
Longtime User
It seems that CallSub can handle only a activity as the first parameter, the inline help of this function also says "not to call subs of code modules". So i only can send messages to an actvity and cannot catch them directly in my code module. But it works with the reflector! In the code module of the list i registered the click message of the Label-CustomView from the subitem code module and let the reflector call a local sub to handle the click event.
BTW Thank you for answering my previous question how to create custom views dynamically! Now all my custom views can work together. I made my own labels, buttons and list. The whole activity is completely dynamic with a layout for each orientation, all view positions are relative and each text fits automatically into each view. The texts are stored in a local database and i can switch the language. The list has a nice item-swap animation im proud of my progress and im excited to go on and load data from the database and fill the list with it :) Thank you for your help!

App01.jpg
 
Upvote 0
Top