B4J Question [B4X Pages] B4XDrawer with CLV with Buttons - Button event does not work

MrKim

Well-Known Member
Licensed User
Longtime User
Pretty much copied from the example.
'load MENU the layout to Root
Drawer.Initialize(Me, "Drawer", Root, 200dip)
Drawer.CenterPanel.LoadLayout("Main")
Drawer.LeftPanel.LoadLayout("MainPageMenu")
[/CODE]
MainPageMenu has a CLV and the CLV_ItemClick event works just fine.
BUT
I added a button and a B4XSwitch (on a pane) from a layout to the CLV.
I added Button_Click and Sw_ValueChanged events to the Main Page from designer but these events do not fire.
The events are trapped because the CLV_ItemClick does not fire if you click the button or the switch.
Clicking the button does nothing, clicking the switch gives the following error.

B4X:
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.Exception: Sub adminmodesw_valuechanged was not found.
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:496)
    at anywheresoftware.b4a.keywords.Common.access$0(Common.java:467)
    at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:541)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.RuntimeException: java.lang.Exception: Sub adminmodesw_valuechanged was not found.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:487)
    ... 9 more
Caused by: java.lang.Exception: Sub adminmodesw_valuechanged was not found.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:98)
    ... 11 more

Any help appreciated.
 

MrKim

Well-Known Member
Licensed User
Longtime User
Can you upload the project?
Since, of course, when I simplified things it worked just fine so I had to duplicate my code more closely to reproduce the problem.
And I solved it but I am not sure it is good practice.
Because the code to populate the CLV gets called from multiple places I had moved that code to a class module. At the time I did this it was a simple CLV.Addtext.

When I decided to make the CLV more complex I needed the to dim one of the views to add text to it and it needed to be in the class module.

The upshot is it works if I move the events to the class module, so the event for the CLV in on the mainpage, but the events for the Views on the CLV are in the class.

I have no idea if this is OK or if it will cause problems - perhaps in B4A or B4i? I have used the 3pagesm with drawer example to demonstrate what I have done.

The drawer is on page 2.

If you bless this mess then I will mark this as solved.

As always thanks for your help.
 

Attachments

  • B4JEventProblem.zip
    12.1 KB · Views: 114
Upvote 0
Top