Set same attributes for many views

Caravelle

Active Member
Licensed User
Longtime User
I hope this request gets through, the last message I sent earlier today seems to have disappeared in the ether - and it took me <ages> to write.

I am sure I have seen the answer to this somewhere in this Forum but I can't find any search terms that will bring it up.

I am looking for an easier way to set the same attributes for a series of views than simply running through them one by one. A loop of some kind, or even a sub which will take the name of the View, like SetAttributes(NameofView). When you have a total of 60 or more edittext boxes spread across different panels in different tabs it gets rather tedious to do this:

Code: Copy
Dim r As Reflector
   TxtUpdSerial.Background = ButtonGradient(Array As Int(Colors.RGB(255, 255, 102), Colors.RGB(240,240,28)))
   r.Target = TxtUpdSerial
    r.RunMethod4("setPadding", Array As Object(0, 1dip, 0, 0), _
       Array As String("java.lang.int", "java.lang.int", "java.lang.int", "java.lang.int"))
   TxtUpdId.Background = ButtonGradient(Array As Int(Colors.RGB(255, 255, 102), Colors.RGB(240,240,28)))
   r.Target = TxtUpdId
    r.RunMethod4("setPadding", Array As Object(0, 1dip, 0, 0), _
       Array As String("java.lang.int", "java.lang.int", "java.lang.int", "java.lang.int"))   
   TxtUpdMaker.Background = ButtonGradient(Array As Int(Colors.RGB(255, 255, 102), Colors.RGB(240,240,28)))
and again
and again
and again...

Thanks

Caravelle
 
There are several ways to do it. You can add all the EditTexts to a List or Map and then iterate over the collection. If you want to run this code on all EditTexts then you can use this code:

Code: Copy
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   RunForEachEditText(Activity)
End Sub


Sub RunForEachEditText(parent As Panel)
   For Each v As View In parent
      If v Is Panel Then
         RunForEachEditText(v)
      Else If v Is EditText Then
         HandleEditText(v)
      End If
   Next
End Sub

Sub HandleEditText(e As EditText)
   e.Text = "aa"
End Sub
 
Upvote 0
Thank you very much Erel. I shall experiment...

Caravelle
 
Upvote 0
Back
Top