Android Question How to change properties of a button dynamically created

raphipps2002

Active Member
Licensed User
Longtime User
If a sub adds several buttons to a scrollview or activity, dynamically, how is it possible to change properties of those buttons from another sub? or is it not? so say
B4X:
Sub a1

For I = 1 to 9

      Dim b a button
      Activity. Addview (b....
Next
End sub

Sub a2


    'B as on a1
    Button1.textsize = 10
    Button2.textsize = 12

End sub
 

sorex

Expert
Licensed User
Longtime User
another method...

you can add tags to the views in your creation loop
later you can loop through the views that are in that scrollview and check the tag values to find the right one.
 
Upvote 0

raphipps2002

Active Member
Licensed User
Longtime User
hi Lucas, that worked a treat....i was really struggling with that one...

and sorcex for his idea
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
If the number of views is given you can declare an array of views.
B4X:
Sub Globals
    Dim Buttons(9) As Button
End Sub

Sub a1
    For I = 0 to 8
        Buttons(I).Initialize("Buttons")
        Buttons(I).Tag = I
        Activity. Addview (Buttons(I), ..
    Next
End sub

Sub a2
    Buttons(0).TextSize = 10
    Buttons(1).TextSize = 12
End Sub
 
Last edited:
Upvote 0

raphipps2002

Active Member
Licensed User
Longtime User
thanks Klaus, both are useful techniques which I have learnt. In my case the number of views is dynamic too so the map idea worked very well
 
Upvote 0

gruizelgruis

Member
Licensed User
Longtime User
If the number of views is given you can declare an array of views.
B4X:
Sub Globals
    Dim Buttons(9) As Button
End Sub

Sub a1
    For I = 0 to 8
        Buttons(I).Initialize("Buttons")
        Buttons(I).Tag = I
        Activity. Addview (Buttons(I), ..
    Next
End sub

Sub a2
    Buttons(0).TextSize = 10
    Buttons(1).TextSize = 12
End Sub


How do I get the index of the button on the click event ?

in VB I would use:
sub button_click(Index as integer)
'// Here I use the index value

end sub

Please advice
 
Upvote 0
Top