I have a primitive question which makes me stupid:
In a panel (pnlInput) I have labels, checkboxes and buttons. With GetAllViewsRecursive I want to handle all views. But the Else command (***) is never processed. It seems all views are labels but they aren't.
B4X:
For Each v As View In pnlInput.GetAllViewsRecursive
If (v Is Label) Then
common1.ScaleText(v)
Else ' ***
If v Is CheckBox Then
v.Left = PanelWidth - 1.5*v.Width
Else
If v Is Button Then
v.Width = PanelWidth - 6%x
v.Left = 3%x
End If
End If
End If
Next
Yes it works correctly, as they ARE all a form of TextView (Label), so it is correct, but you want to know which particular one it is. Therefore you need to check the lowest level first.
So if I have in a panel some EditTexts, Buttons and Labels and want only to set the TextSize of the labels the code must be:
B4X:
For Each v As View In pnlInput.GetAllViewsRecursive
If (v Is EditText) Then
' DoNothing
Else
if (v Is Button) then
' DoNothing
else
if (v Is Label) then
v.TextSize = 32
End If
End If
End If
Next
OK, in future I know in which sequence to use the commands "If .. Is ... Then" within
"GetAllViewsRecursive". But that is for me a workaround.
That a Label is a subclass of TextView is right, but the statement "v Is Label" with the result "True" above is wrong - for me. V in this case is a EditText and NOT a Label. The description of the command "Is" is not so helpful - for me.
If it's critical, you could always try doing a more thorough compare:
B4X:
Sub IS2(V As View,CompareTo As String) As Boolean
Select CompareTo.ToUpperCase
Case "LABEL"
If(GetType(V) = "android.widget.TextView") Then Return True
Case "CHECKBOX"
If(GetType(V) = "android.widget.CheckBox") Then Return True
Case "EDITTEXT"
If(GetType(V) = "android.widget.EditText") Then Return True
End Select
Return False
End Sub
It is not critical because I know this problem now. In another example I read all views of a panel with "GetAllViewsRecursive" and wanted to set the textsize of all labels and wondered that the textsize of the buttons also were scaled. Now I know why.
The result of IS2 is the behaviour that I expect of the command "Is" - like described.