Android Question Can't seem to pass tag for Toggle Button

David Elkington

Active Member
Licensed User
Longtime User
Hope someone can help.

I am dynamically adding toggle buttons to a panel from a database, but I would like to pass the Tag to the click event as it basically decides whether it will be tri-state or Red on "No" for critical entries. I have the code below

<code>
Dim b AsToggleButton

Dim sf AsStringFunctions

sf.Initialize
b = Sender
b.Initialize("")

Select Case sf.Left(b.Tag,3)
Case"TG2" 'Two way, not critical

Case"TG3" 'Two way, critical

If b.Checked = False Then

b.Color=Colors.Red

b.Tag=sf.left(b.Tag,11) & "RD"

Else

b.Color = Colors.DarkGray

b.Tag=sf.left(b.Tag,11) & "DG"

EndIf

</code>

But when I interrogate b.tag, it says it is null? Am I doing something wrong.?
 

klaus

Expert
Licensed User
Longtime User
In the For / Next block you must Dim the different View in each iteration, not only in Globals!

B4X:
For i = 0 To cursor.RowCount-1
     Private tglQuestion As ToggleButton
     Private lbl As Label
     Private txt As EditText

How do you copy the code into the posts?
You should use:

upload_2017-11-1_12-7-17.png

And copy the code from the IDE.
 
Upvote 0

David Elkington

Active Member
Licensed User
Longtime User
Thanks Klauss, I will try that to see if it make it more solid, it seems to be working presently. Noted on the code segment, I was using <code> not
B4X:
 
Upvote 0
Top