Android Question CheckboxCheckedChange cannot be called

jalvarez

Member
Licensed User
Longtime User
Hi everyone!,

I've searched and reviewed all about checkbox threads and tested each solution, but I cannot turn this control to true. I'm reading a SQLite Db field that has a value of 1 or 0 and once filtered I need that for each value of 1, the control that is part of a Customlistview takes the state of true, as If I would have touched it.
Please enlightme with another solution to activate the checkbox by code in runtime. Thanks
 

DonManfred

Expert
Licensed User
Longtime User
We cannot help without seeing your code. Post a small project which shows the problem.

You dont need to call checked_change (it´s an event).
You just need to set the Checked Property of your Checkbox to true.
 
Upvote 0

jalvarez

Member
Licensed User
Longtime User
Sorry DonManfred,

Attached project; I'll thank you if could you help me to change this checkbox by code, as I wrote, I reviewed each and every thread but I cannot understand why this stuff refuses to run. Thanks again.

Regards
 

Attachments

  • Milano.zip
    182.7 KB · Views: 191
Upvote 0

jalvarez

Member
Licensed User
Longtime User
I've just attached a screenshot of my project; I've included the setting of the checkbox1 to true, and ran the program and crashed. This maybe helps.
 

Attachments

  • Screenshot - 23_05_2017 , 09_11_28 a_m.jpg
    Screenshot - 23_05_2017 , 09_11_28 a_m.jpg
    225.1 KB · Views: 194
Upvote 0

jalvarez

Member
Licensed User
Longtime User
DonManfred,

Having reviewed the project I realize that you need the SQLite Db as well, so I attach the file to this post, please tell me what else do you need for your analysis. Thank again. I hope you can open it.
 

Attachments

  • Checklist.zip
    141.8 KB · Views: 189
Upvote 0

jalvarez

Member
Licensed User
Longtime User
DonManfred, Thanks again, the problem is that the instruction Checkbox1.Checked = true doesn't work at runtime, I don't know what version of Android you have as default, maybe this could be, I test my code on a LG G65 with Android 4.2.2 Except this everything is OK, the app crash and sends the next messages:

Logger connected to: LGE LG-D280
--------- beginning of /dev/log/main
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
--------- beginning of /dev/log/system
ExecuteMemoryTable: SELECT Supervisor FROM Supervisores
ExecuteMap: Select Tienda,Supervisor from Supervisores WHERE Supervisor = ?
Error occurred on line: 247 (CustomListView)
java.lang.RuntimeException: Object should first be initialized (View).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.ViewWrapper.getParent(ViewWrapper.java:251)
at de.amberhome.slidemenuexample.customlistview._getitemfromview(customlistview.java:71)
at de.amberhome.slidemenuexample.main._checkbox1_checkedchange(main.java:1036)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.objects.CompoundButtonWrapper$1.onCheckedChanged(CompoundButtonWrapper.java:44)
at android.widget.CompoundButton.setChecked(CompoundButton.java:127)
at anywheresoftware.b4a.objects.CompoundButtonWrapper.setChecked(CompoundButtonWrapper.java:55)
at de.amberhome.slidemenuexample.main._createlistitem(main.java:1195)
at de.amberhome.slidemenuexample.main._checklist_click(main.java:1147)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4442)
at android.view.View$PerformClick.run(View.java:18473)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It fails inside the CreateListItem sub when you set CheckBox1.Checked = True.

The reason that it fails is that the CheckedChange event is raised before the item was added to clv2.
The error happens here:
B4X:
clv2.GetItemFromView(Sender)

You have several options. You can call Checkbox1.Checked = True after you add the item or add a global variable and use it to ignore the CheckedChange event until all items were loaded.
 
Upvote 0

jalvarez

Member
Licensed User
Longtime User
Erel, Thanks for your reply, both: my buying request (I'm waiting for the client's money) and for my problem, unfortunately, cannot understand how can I delay the event Checkbox1_CheckedChange using a global variable or the first one option, please, could you explain me how to do it?. Thanks in advance. Regards.

jalvarez
 
Upvote 0

jalvarez

Member
Licensed User
Longtime User
Move the 'Checkbox1.Checked = True' line from the CreateListItem and call it right after the item is added to the list.

The second option is to ignore the event with a global variable:
B4X:
Sub Checkbox1_CheckedChange(...)
If IgnoreEvent = True Then Return
...
Erel,

Thanks, the event Checkbox1_CheckedChange only happens when I touch the checkbox control, I tested your suggestions but simply nothing happens, The idea is to replicate the touch event for each and every panel (there are 102) that composes the CustomListView according to past events that were saved as 1 on field estatus in Checklist database. I apologize for this explanation to you but I cannot understand how a simple control's change of status can be so difficult to implement. I've thinked about change checkbox control to another one that has the click event or the like. Sorry, but simply I cannot understand. Regards.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
We can see from the stack trace that the error happened when you set the checked property. This also causes the event to be raised.

at de.amberhome.slidemenuexample.main._checkbox1_checkedchange(main.java:1036) <-- Checkbox1_CheckedChange event.
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.objects.CompoundButtonWrapper$1.onCheckedChanged(CompoundButtonWrapper.java:44)
at android.widget.CompoundButton.setChecked(CompoundButton.java:127)
at anywheresoftware.b4a.objects.CompoundButtonWrapper.setChecked(CompoundButtonWrapper.java:55) <-- CheckBox.Checked = ...
at de.amberhome.slidemenuexample.main._createlistitem(main.java:1195) <---CreateListItem sub
 
Upvote 0

jalvarez

Member
Licensed User
Longtime User
Hi Erel!,

Sorry for not reply promptly, I solved the problem viewing Informatix code about set all checkboxes to true, so, I cannot find how to close this thread and start another one. Thanks and best regards.
 
Upvote 0
Top