looping on activity elements

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
:sign0085:

hi,

can anyone help (a sample will be most appreciated) on how do i loop on all labels & edittext elements in my activity ?
what i want to do is to loop across all these elements and change their justification say to from right to left or even better to the opposite (right to left & left to right)

thanks...
 

derez

Expert
Licensed User
Longtime User
do it like this, here I set the font size to all views which have text, after assigning the right text in their tags:

B4X:
sub set_size
Dim V As View
Dim p As Panel
Dim BT As Button
Dim E As EditText
Dim R As RadioButton
Dim Sp As Spinner
Dim L As Label

For i = 0 To Activity.NumberOfViews - 1
   V = Activity.GetView(i)
      Select V.Tag
         Case "button"
            BT = V
            BT.TextSize = fontsize
         Case  "et"
            E = V
            E.TextSize = fontsize
         Case  "label"
            L = V
            L.TextSize = fontsize
         Case "rb" 
            R = V
            R.TextSize = fontsize
         Case "spinner"
            Sp = V
            Sp.TextSize = fontsize
         Case "panel"
            p = V
            SetPanels(p)   ' do the same for all panel's views
   End Select 
Next
end sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Another option:
B4X:
For i = 0 To Activity.NumberOfViews - 1
 Dim L As Label
 If Activity.GetView(i) Is Label Then
  L = Activity.GetView(i)
  L.TextSize = ...
  L.Gravity = ...
End If
Next

Is keyword checks the object type. Button, EditText, CheckBox, RadioButton and ToggleButton are actually subtypes of Label. So they all can be treated as labels.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
thanks guys

the issue i was interested was not text size but the text style > horizontal alignment

this is really killing me :(
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
thanks!
will this loop on all fields or just the current view ?
i mean i would like it to loop over ALL project elements
otherwize i will have to do it each time a layout is loaded, in that case is there a form_load like sub ? like in .net visual studio an even that is triggered upon loading the form so i can put the calling there
hope i made myself clear

the reason i need it is for devices that do not have a locale for hebrew so all elements are wrongly justified even if i stated them to right they will be to left so i want to put a checkbox to let the user check it if the justification needs to be altered

do you have a better idea ?
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
signing question

another thing - how do i sign my apk so i can upload it ?
when i try to upload i get an error saying it is a debug key
thanks
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
thanks pal - the signing link was a life saver :)

any one can help on iif ?

the gravity issue was nice but did not really solve my problem as i need an easier way to support devices with "real" hebrew and device just with hebrew support as justification is also an issue...

and finally - how do you guys make it to support screens of different sizes without having the app look messy ?

i had it very nicely on my samsung S1 & S2 but on S3 & Note it is not as nice ... as screens are not same size

thanks...
 
Upvote 0
Top