Android Question Checkbox Logic Reversed?

mpearson

Member
Licensed User
Longtime User
Did something change with checkboxes? I rebuilt an application I've been running for a while and the checkbox logic has reversed. I made the following simple test app to isolate the issue. When you check the box and it enters chkOne_CheckedChange, it logs false. That's backwards, right?

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private chkOne As CheckBox
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
   
End Sub

Sub Activity_Resume
   
End Sub

Sub chkOne_CheckedChange(Checked As Boolean)
    Log(chkOne.Checked)
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello @mpearson sorry but you have something wrong there as nothing as changed. Try the untested code below, no layout file is needed.
Checked will equal True
Unchecked will equal False
B4X:
Sub Globals
    Dim ChkBox1 As CheckBox
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ChkBox1.Initialize("ChkBox1")
    Activity.AddView(ChkBox1, 0dip, 200dip, 10%x, 30dip)
End Sub

Sub ChkBox1_CheckedChange(Checked As Boolean)
    Log(Checked)
End Sub

Enjoy...
 
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
It's probably because it is checked as the default in the Visual Designer when the Layout was put together.
So, when clicked, it would be unchecked?
Just an idea......:confused:
 
Upvote 0

mpearson

Member
Licensed User
Longtime User
Hello @Peter Simpson
Thanks for your response. Yes, I had that incorrect. Going too fast. But I still get the opposite result.

@jimmyF
Thanks for the idea, but it is unchecked in the visual designer.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
B4X:
When you check the box and it enters chkOne_CheckedChange, it logs false.

Sleep a little, then Log. I see in own application that I set Sleep (50). Obviously, this is more than enough
 
Upvote 0

mpearson

Member
Licensed User
Longtime User
@Semen Matusovskiy thanks but that didn't fix it. I have this working on an app I've been running for about a year. It wouldn't compile at all earlier due to an update, so I had to update the below from 27 to 28. That seems to be when the checkbox behavior changed.


upload_2018-9-30_20-0-30.png
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Try an attached zip. It works Ok on my PC. I use android-27.jar and mavens 27.1.1.

Actually, I also automatically install new mavens 28.0.0. But I had a copy of sdk folder, so I restored.

BTW, I checked with new mavens and android-28. I don't see troubles. CheckBox1.Checked becomes the same as input parameter Checked.
 

Attachments

  • test.zip
    8.8 KB · Views: 164
Last edited:
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Have you got both the original Android SDK and the updated B4A SDK Manager installed on your developer PC/Laptop, or just the B4A SDK Manager because you previously completely removed the original Android SDK?

And no, I'm not denying that something has obviously changed, just attempting to help you if you want it. Lots of developers still had the older SDK on their machines which caused them no end of troubles until they removed it and stuck to only one, the B4A SDk manager.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
It looks that new mavens are first official release of 28.0.0. At least internally they name itself so <version>28.0.0</version>
Previously was 28.0.0-alpha1, alpha2, alpha3.

I have both variants - complete SDK folder according September 17 and current with mavens 28.0.0.
To check what happens with new mavents I temporary rename folders and set android-28 in pathes.

I think, if you support actual app, better not to risk and to use old mavens with android-27.
If you write a new program, may be there is a reason to use new mavens with android-28.

BTW, Android Studio with default settings does not download so new mavens.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Checked with one of my apps using 5 checkboxes with an logic that if one checks one of the 5, other ones will be un-checked.

Be careful because if you check a box by code, there might be several actions fired. I helped myself with a variable called "ItWasMe". If I change a cb by code, I set it to true to prevent any code in the event.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Windows, as I remember, at first changes a state of Checkbox and then generates an event.
Android, obviously, uses reverse order.

Meanwhile (Checked As Boolean) is correct and actually you don't need to wait a moment, when Android will change a state.
If Checked = True, then turn off another checkboxes.
 
Upvote 0

mpearson

Member
Licensed User
Longtime User
Try an attached zip. It works Ok on my PC. I use android-27.jar and mavens 27.1.1.

Actually, I also automatically install new mavens 28.0.0. But I had a copy of sdk folder, so I restored.

BTW, I checked with new mavens and android-28. I don't see troubles. CheckBox1.Checked becomes the same as input parameter Checked.
Thanks. I'll check this out tonight.
 
Upvote 0

mpearson

Member
Licensed User
Longtime User
Have you got both the original Android SDK and the updated B4A SDK Manager installed on your developer PC/Laptop, or just the B4A SDK Manager because you previously completely removed the original Android SDK?

And no, I'm not denying that something has obviously changed, just attempting to help you if you want it. Lots of developers still had the older SDK on their machines which caused them no end of troubles until they removed it and stuck to only one, the B4A SDk manager.
No, just updated B4A SDK Manager. I've been running that for several months now.
 
Upvote 0

mpearson

Member
Licensed User
Longtime User
Try an attached zip. It works Ok on my PC. I use android-27.jar and mavens 27.1.1.

Actually, I also automatically install new mavens 28.0.0. But I had a copy of sdk folder, so I restored.

BTW, I checked with new mavens and android-28. I don't see troubles. CheckBox1.Checked becomes the same as input parameter Checked.

Here is a link to what I'm seeing. Are you recommending I revert back?
https://drive.google.com/open?id=1zdusOuqIB-COxJBUd7lPVVeyIBj0_Tk_
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
I would say to delete your Android folder(s) and reinstall the whole of the SDK again, and make sure that your Java is up to date too. I always use the newest javac.exe and also the newest android.jar too. The issue isn't with B4A, but I would start with your Android folder, but that's me. I've never come across your issue before, I don't think that I've even read about it before either...
 
Upvote 0

mpearson

Member
Licensed User
Longtime User
I would say to delete your Android folder(s) and reinstall the whole of the SDK again, and make sure that your Java is up to date too. I always use the newest javac.exe and also the newest android.jar too. The issue isn't with B4A, but I would start with your Android folder, but that's me. I've never come across your issue before, I don't think that I've even read about it before either...
That may be the way to go. It's definitely weird. I'll give it a shot later. Thanks for the help.

Edit: Removing and reinstalling resolved the issue. Thanks for the suggestion.
 
Last edited:
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
As I see, my test works correctly and confirms that you can use Checked parameter in Sub chkOne_CheckedChange(Checked As Boolean). Android will correct chkOne.Checked a little later.

Personally I prefered to revert back to mavens 27.*.* and do not want to risk. The last signal was a confict between Design Support library, which I use, and new mavens.
Android-P is not stable, why to hurry ? We make a lot of own mistakes, addition in the form of errors or incompatibilities is clearly superfluous.
 
Upvote 0
Top