Android Question Custom list view B4x switch disable

giggetto71

Active Member
Licensed User
Longtime User
Hi guys,
I have a Custom List view made with cards. Each card has several views inside and one B4X switch. At runtime I can manipulate all objects of each card leveraging the "Tag" property (what I do I search for the tag and get the index which I then use as shown below).Unfortunately I cannot do that with the B4X switch. My desire would be to enable/disable the switch at run time given the index of the card

B4X:
..........
' example for a label
Dim pnl As B4XView, v As B4XView,TempLbl As Label
pnl = CLV1.GetPanel(CardIndex).GetView(0) ' this is the card'
v = pnl.GetView(LabelIndex) ' previously got from the tag
TempLbl = v
TempLbl.enabled = false
......

in this case I can disable the label with a certain index.
Unfortunately I am not able to do that with the b4x switch even if I know its index. The below code crashes

B4X:
....
Dim pnl As B4XView, v As B4XView,TempLbl As Label,TempSw as B4XSwitch
pnl = CLV1.GetPanel(CardIndex).GetView(0) ' this is the card'
v = pnl.GetView(SwitchIndex)
TempSw = v
TempSw.enabled = false
..............

Attached the error log

......
Error occurred on line: 1749 (Main)
java.lang.RuntimeException: Field: ba not found in: anywheresoftware.b4a.BALayout
at anywheresoftware.b4a.shell.Shell$FieldCache.getField(Shell.java:923)
at anywheresoftware.b4a.shell.Shell.getField(Shell.java:697)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at gigiosoft.MQTTAlert.main._getcardsobjindexes(main.java:1113)
at gigiosoft.MQTTAlert.main._activity_create(main.java:993)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at gigiosoft.MQTTAlert.main.afterFirstLayout(main.java:104)
at gigiosoft.MQTTAlert.main.access$000(main.java:17)
at gigiosoft.MQTTAlert.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7078)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)



Any idea? thanks!
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
I have added the code that fails. again thanks for any help
DId you try something like this. I did not have a chance to fully test:
B4X:
Dim pnl As B4XView, v As B4XView,TempLbl As Label,TempSw as B4XSwitch
pnl = CLV1.GetPanel(CardIndex).GetView(0) 
For Each v As B4XView In pnl.GetAllViewsRecursive
        If v.Tag Is B4XSwitch Then
            Dim sw As B4XSwitch = v.Tag
            sw.Enabled=False
        End If
    Next
 
Upvote 0
Top