Android Question Enumerate all panels in a layout

Sanxion

Active Member
Licensed User
Longtime User
Hi all

I am attempting to enumerate all the panels with a specific tag in a layout and then center them with the following:

' Center all the lesson panels
For Each pnl As Panel In Activity

Dim PanelTag As String
PanelTag = pnl.Tag

If PanelTag.SubString2(0,5) = "Lesson" Then
pnl.Left = (Activity.Width - pnl.Width) / 2
pnl.Top = (Activity.Height - pnl.Height) / 2
End If

Next

However, the following error is occurring:

java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.view.ViewGroup

Any ideas?
 

eurojam

Well-Known Member
Licensed User
Longtime User
you can loop trough all the views in your activity and check if it is a panel like this:
B4X:
For Each v As View In Activity
    If v Is Panel Then   

        Dim PanelTag As String
        PanelTag = v.Tag

        If PanelTag.SubString2(0,5) = "Lesson" Then
          v.Left = (Activity.Width - v.Width) / 2
          v.Top = (Activity.Height - v.Height) / 2
        End If
    End If

Next
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
you can loop trough all the views in your activity and check if it is a panel like this:
B4X:
For Each v As View In Activity
    If v Is Panel Then

        Dim PanelTag As String
        PanelTag = v.Tag

        If PanelTag.SubString2(0,5) = "Lesson" Then
          v.Left = (Activity.Width - v.Width) / 2
          v.Top = (Activity.Height - v.Height) / 2
        End If
    End If

Next


[off topic]
If PanelTag.SubString2(0,5) = "Lesson" Then
If PanelTag.SubString2(0,6) = "Lesson" Then

You can use:
If PanelTag.StartsWith("Lesson") Then

;)
 
Last edited:
Upvote 0
Top