Android Question Help with xCustomListView with custom CheckBox

rraswisak

Active Member
Licensed User
Hi all,

My B4A app use xCustomListView from here and i also create custom checkbox, i want to change of using standard/built-in checkbox with my own custom checkbox.
I want the custom checkbox act just like standard checkbox in this sample

I get this error:

B4X:
Sub b4aCheckBox1_ValueChanged (Value As Boolean)
   Dim index As Int = clv2.GetItemFromView(Sender) '<--- error here
   Dim pnl As B4XView = clv2.GetPanel(index)
   Dim chk As B4XView = pnl.GetView(2)
   MsgboxAsync($"Item value: ${clv2.GetValue(index)} Check value: ${chk.Checked}"$, "")   
End Sub

The log says:

Logger connected to: 192.168.9.101:5555
--------- beginning of /dev/log/main--------- beginning of /dev/log/system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Class not found: anywheresoftware.b4a.samples.customlistview.customlistview, trying: b4a.example3.customlistview
Class not found: anywheresoftware.b4a.samples.customlistview.customlistview, trying: b4a.example3.customlistview
** Activity (main) Resume **
customlistview_getitemfromview (java line: 388)
java.lang.ClassCastException: b4a.example3.b4acheckbox cannot be cast to android.view.View
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:48)
at anywheresoftware.b4a.objects.B4XViewWrapper.getParent(B4XViewWrapper.java:117)
at b4a.example3.customlistview._getitemfromview(customlistview.java:388)
at b4a.example3.main._b4acheckbox1_valuechanged(main.java:378)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1038)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:993)
at b4a.example3.b4acheckbox._dotpanel_click(b4acheckbox.java:120)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
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:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)


Any help would be appreciated and thank you for your time
 

Attachments

  • xCustomListViewCheckBox.zip
    361.6 KB · Views: 197

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub b4aCheckBox1_CheckedChange(Checked As Boolean)
    Dim chk As b4aCheckBox = Sender
    Dim index As Int = clv2.GetItemFromView(chk)
    Dim pnl As B4XView = clv2.GetPanel(index)
    'Dim chk As B4XView = pnl.GetView(2)
    'MsgboxAsync($"Item value: ${clv2.GetValue(index)} "$, "")
    Dim content As String = $"Item value: ${clv2.GetValue(index)} Check value: ${chk.Checked(True)}"$
    MsgboxAsync(content, "")
End Sub

You Checked inside the b4acheckbox is not a Property. It is a method which expect true/false as a parameter

You need to add Checked as a property (setup getter and setter in the class) to get the value later...
 

Attachments

  • new.zip
    18.5 KB · Views: 222
Upvote 0

rraswisak

Active Member
Licensed User
Hi DonManfred,

Sorry for late respond, i have check the file you attached, but unfortunatelly still getting this error.
As the code from above the b4aCheckBox does not have CheckedChange event, it use ValueChange event instead.

I believe the problem as mention at the log was the b4acheckbox is not android.view type, but i don't know how to resolve this


*why i need this b4acheckbox ? my app background mostly has white background, so if i use standard checkbox the box color is hard to see so user won't realize there is an checkbox to switch. Yes the xCustomListView has ItemClick Event, but i want to make sure the action was execute after the CheckBox was click


Thank you
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
I believe the problem as mention at the log was the b4acheckbox is not android.view type, but i don't know how to resolve this

Can you use something like this?

B4X:
Sub b4aCheckBox1_ValueChanged (Value As Boolean)
       Dim chk As b4aCheckBox = Sender
       Dim index As Int = clv2.GetItemFromView(chk.GetBase)
       Log(clv2.GetValue(index))
       Log(chk.isChecked)

...
 
Last edited:
Upvote 0
Top