B4J Question How to get checkbox state after addnode???

Pietro Pancino

Member
Licensed User
Longtime User
Hi Every Body,

I created a function that create checkbox in a tabpage.
Each created checkbox ID is defined like this : plan1_x_y
Those checkbox are organised like this (see join picture).
I need to check each line of checkbox to get a unique 11 bit value. For example:
Checkbox line 1 column 1 (ID = plan1_1_1) = bit10
Checkbox line 1 column 2 (ID = plan1_1_2) = bit9
and so on until last column and this for each lines.

My problem is that I don't know how to get .ID the value of each Checkbox calling by is name.
Is it possible to dynamically create an object name in order to get his ID?

Like this maybe :) ????
For y = 1 To nb_y
For x = 1 To nb_x
Log (("plan1_"&y&"_"&x).id)
Next
Next


If anyone know it will be helpfull ;-)

Following my sample code to create checkboxes
Pietro

Here sample code to create the checkbox.
CreateCheckboxes(w_plan, "plan1", 222,39)
CreateCheckboxes(w_plan, "plan2", 222,202)
CreateCheckboxes(w_plan, "plan3", 222,367)


Here the chekbox create function

Sub CreateCheckboxes(Parent As TabPage, nom As String, x_org As Int,y_org As Int) As CheckBox(,)
' screen increment on x
Dim inc_x As Int = 26
Dim inc_y As Int = 19

' coordonnées curseur
Dim le_x As Int = x_org
Dim le_y As Int = y_org

' increment en y
Dim cb(nb_x+1, nb_y+1) As CheckBox


For y = 1 To nb_y
le_y = le_y +inc_y
le_x = x_org
For x = 1 To nb_x

Dim chk As CheckBox
chk.Initialize("chk")
Parent.Content.AddNode(chk, le_x, le_y ,-1,-1)
chk.Text = ""
chk.Id = nom &"_"& y &"_"& y
chk.Checked=True
cb(x, y) = chk
' Log ("Creation of "&chk.Id)
le_x = le_x + inc_x
Next
Next
Return cb
End Sub
 

Attachments

  • Capture_chekbox.JPG
    Capture_chekbox.JPG
    110.9 KB · Views: 248

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Hi!

Ir seems that everything is okey. You should use the tag property of the nodes

B4X:
Dim cb as checkbox 
Cb.initialize("grid") 
'Array of x and y 
Dim arr() as string = array as string(0,1) 
Cb.tag = arr

Get the tag later on.

B4X:
Dim arr() as string = cb.tag 
Log("x "&arr(0) &" y " & arr(1))

If you search for tic tac toe in b4a you will find a nice example from erel.
 
Upvote 0

Pietro Pancino

Member
Licensed User
Longtime User
I Enrique!

Sorry for my late answer, I was out with a customer...

I don't understand your sample code. And the meaning of tag...

My code generate checkboxes with Id like this plan1_x_y where x is the row and y the column of the checkbox.
In order to obtain the binary value of each line, i need to know if each Checkbox is true or false to assign the value of each bits:
plan1_1_1 = 2048
plan2_1_2 = 1024
...
plan2_1_11 = 1 etc...
To Construct this value I need to make a for-next loop to obtain the value of each checkbox of a line by using its ID. But I don't know to do it.
Here is my idea:

dim the_name as string
for x = 1 to 6
For y = 1 to 11
' construction of the name of the checkbox
the_name = "plan1_" & x & "_" & y
' test the checkbox state
if the_name.id = true then
......
else
.....
end if
next
next

Hopping you will understand what I want to do...

:) Pietro
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Hi Pietro!

Attached you will find an example on how the tag works, AFAIK the id of the nodes in B4J are related to the Scene builder layouts i do not know if they should be considered as an unique ID.
 

Attachments

  • example.zip
    2.4 KB · Views: 240
Upvote 0

Pietro Pancino

Member
Licensed User
Longtime User
hi Enrique!
After a long time off I did it! Based on your sample code.
You can set à value in a textarea and get the result in binary through the checkbox. Look it's working almost fine.
Thank you! It's not very easy to understand how it's run but after some hours...
:) Pietro
 

Attachments

  • example_tag.zip
    5.1 KB · Views: 243
Upvote 0
Top