B4A Library [B4X] [XUI] AS Checkbox

This is a simple cross platform Checkbox.

If you need a checkbox with text, then check out the AS_CheckBoxAdvanced

I spend a lot of time in creating views, like this and to create a high quality view cost a lot of time. If you want to support me and further views, then you can do it here by Paypal or with a coffee. :)
B4j: jXUI,JavaObject
B4a: XUi,StringUtils,XUI Views (2.40+)
B4i: iXUI,XUI Views (2.40+)

Screenshot_20200903-003723.jpg
Screenshot_20200903-003753.jpg
ezgif.com-crop.gif

2020-09-03-10-17-41.gif
20-09-03-10-24-58.gif

Disabled style:
Screenshot_20201127-101856.jpg


AS_Checkbox
Author: Alexander Stolte
Version: 2.00
  • ASCheckbox
    • Events:
      • CheckedChange (Checked As Boolean)
    • Fields:
      • mBase As B4XView
      • Tag As Object
    • Functions:
      • Base_Resize (Width As Double, Height As Double)
      • DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
        Base type must be Object
      • Initialize (Callback As Object, EventName As String)
      • SetIcon (icon As String, isfontawesome As Boolean)
    • Properties:
      • BorderCornerRadius As Int [write only]
      • BorderWidth As Int [write only]
      • Checked As Boolean
      • Checked2 As Boolean [write only]
        Without the CheckedChange Event
      • CheckedAnimated As Boolean [write only]
      • CheckedBackgroundColor As Int [write only]
      • DisabledBackgroundColor As Int
      • DisabledIconColor As Int
      • Enabled As Boolean
      • IconColor As Int
      • isEvent As Boolean
      • isFillUncheckedBackgroundColor As Boolean
      • isFontAswesome As Boolean
      • isHaptic As Boolean
      • isround As Boolean
      • Theme As AS_CheckBox_Theme [write only]
      • Theme_Dark As AS_CheckBox_Theme [read only]
      • Theme_Light As AS_CheckBox_Theme [read only]
      • UncheckedBackgroundColor As Int
      • UncheckedIconColor As Int
Changelog
  • 1.00
    • Release
  • 1.01
    • Add CheckedAnimated
    • B4J BugFix Label Size was resizing if the font was to big
  • 1.02
    • Add HapticFeedback
  • 1.03
    • Checked was readonly
  • 1.04
    • Add DisabledBackgroundColor property and designer property
    • Add DisabledIconColor property and designer property
    • Add Enable property - enable or disable the view
      • Screenshot_20201127-101856.jpg
    • no animation if you change the checked state via code
  • 1.05
    • B4I No Jump animation if the BorderCornerRadius > 0 (the radius cannot be held during animation, so it looks buggy when you have e.g. a circle)
    • BugFix - Enabled = False, now the view is disabled, no touch gestures allowed
  • 1.06
    • Intern Function IIF renamed to iif2
  • 1.07
    • Add DesingerProperty Checked - if true then the checkbox is checked
    • Add DesingerProperty Enabled - if false then the checkbox is disabled
      • On B4A and B4J the core enabled property in the designer is not used anymore
    • BugFixes
    • Intern Function iif2 removed and the core iif is now used
      • B4A V11+ - B4J V9.10+ - B4I V7.50+
  • 1.08
    • BugFix - When creating the view the CheckedChange event was triggered with parameter "False"
  • 1.09
    • Add Event property - If False then the CheckedChange event is not triggered
  • 1.10
    • Base_Resize is now public
  • 1.11
    • Intern Improvements
    • Add get and set IconColor
  • 1.12
    • Add set Checked2 - Without the CheckedChange Event
  • 2.00 (read more)
    • Add Designer Property FillUncheckedBackgroundColor
    • Add Designer Property UncheckedBackgroundColor
    • Add Designer Property UncheckedIconColor
    • Add Designer Property Round
      • Default: False
    • Add set Theme
    • Add get Theme_Dark
    • Add get Theme_Light
    • Add Designer Property ThemeChangeTransition
      • Default: None
Have Fun :)
 

Attachments

  • AS Checkbox Example.zip
    177.7 KB · Views: 831
  • ASCheckbox.b4xlib
    4.1 KB · Views: 51
Last edited:

LWGShane

Well-Known Member
Licensed User
Longtime User

Alexander Stolte

Expert
Licensed User
Longtime User
Update
  • 1.04
    • Add DisabledBackgroundColor property and designer property
    • Add DisabledIconColor property and designer property
    • Add Enable property - enable or disable the view
      • Screenshot_20201127-101856.jpg
  • no animation if you change the checked state via code
Tip: if you uncheck the view "Enable" Property in the designer then the view is disabled
 

red30

Well-Known Member
Licensed User
Longtime User
When I add text in designer, it doesn't show up in ASCheckbox. Why? Is it possible to somehow add text after the "checkmark"?
I cannot get the index when ASCheckbox is in CustomListView.
B4X:
Sub ASCheckBox1_CheckedChange(Checked As Boolean)
    Dim index As Int = allclv.GetItemFromView(Sender)
    Log(index)
End Sub
I get an error:
B4X:
mod4_ascheckbox1_checkedchange (java line: 609)
java.lang.ClassCastException: red.123.ascheckbox cannot be cast to android.view.View
    at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:89)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getParent(B4XViewWrapper.java:186)
    at b4a.example3.customlistview._getitemfromview(customlistview.java:413)
    at red.ap.expert.bestapp.mod4._checkbox11_checkedchange(mod4.java:609)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1082)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1037)
    at red.ap.expert.bestapp.ascheckbox._checkedchange(ascheckbox.java:298)
    at red.ap.expert.bestapp.ascheckbox$ResumableSub_Check.resume(ascheckbox.java:285)
    at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1704)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6865)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:504)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
How can I get the index?
 

Alexander Stolte

Expert
Licensed User
Longtime User
When I add text in designer, it doesn't show up in ASCheckbox. Why?
Because the view is only the checkbox, not checkbox + text.
Add a simple label after the checkbox and done.

Sub ASCheckBox1_CheckedChange(Checked As Boolean) Dim index As Int = allclv.GetItemFromView(Sender) Log(index) End Sub
i dont know what this code does, but it should be this:
B4X:
Sub ASCheckBox1_CheckedChange(Checked As Boolean)
    Dim tmp_checkbox As ASCheckBox = Sender
    Dim index As Int = allclv.GetItemFromView(tmp_checkbox.mBase)
    Log(index)
End Sub
 

Alexander Stolte

Expert
Licensed User
Longtime User
Update
  • 1.05
    • B4I No Jump animation if the BorderCornerRadius > 0 (the radius cannot be held during animation, so it looks buggy when you have e.g. a circle)
    • BugFix - Enabled = False, now the view is disabled, no touch gestures allowed
 

Alexander Stolte

Expert
Licensed User
Longtime User
Update
  • 1.07
    • Add DesingerProperty Checked - if true then the checkbox is checked
    • Add DesingerProperty Enabled - if false then the checkbox is disabled
      • On B4A and B4J the core enabled property in the designer is not used anymore
    • BugFixes
    • Intern Function iif2 removed and the core iif is now used
      • B4A V11+ - B4J V9.10+ - B4I V7.50+
 
Last edited:

LWGShane

Well-Known Member
Licensed User
Longtime User
Intern Function iif2 removed and the core iif is now used
  • B4A V9.10+ - B4J V9.10+ - B4I V7.50+

IIf was introduced with B4A 11.0. (Also B4A 9.10 doesn't exist.)
 

Alexander Stolte

Expert
Licensed User
Longtime User
Update
  • 1.09
    • Add Event property - If False then the CheckedChange event is not triggered
This is useful if you want to check checkboxes in the code, but don't want the code to be triggered in the event, because you would then make an INSERT statement, for example.
 

cyware

New Member
Licensed User
Longtime User
Nice one but: would it be difficult to expose the top/left etc fields? Sometimes you want to move it programmatically.
 

Alexander Stolte

Expert
Licensed User
Longtime User
Update
  • 2.00
    • Add Designer Property FillUncheckedBackgroundColor
    • Add Designer Property UncheckedBackgroundColor
    • Add Designer Property UncheckedIconColor
    • Add Designer Property Round
      • Default: False
    • Add set Theme
    • Add get Theme_Dark
    • Add get Theme_Light
    • Add Designer Property ThemeChangeTransition
      • Default: None
Round
Make your checkbox round
1733662051113.png


Theming
as in almost all of my views, there is now a built-in dark/light mode that you can easily customize yourself
B4X:
ASCheckbox1.Theme = ASCheckbox1.Theme_Light
B4X:
ASCheckbox1.Theme = ASCheckbox1.Theme_Dark

FillUncheckedBackgroundColor
If the checked = False

  • If False, then only the border is filled with the color
  • If True, the checkbox is filled with the color
1733662428894.png
 
Top