Android Question Is a button view and label view the same thing???

Steve Miller

Active Member
Licensed User
Longtime User
I'm looping through the views on a tab and when it comes to a button, it is dropping into the label logic.

v is the view. When the view coming through is a button, it is dropping into the "v is Label" code. Why?


B4X:
    Select Case True
        Case v Is TabHost
            Dim th As TabHost
            Dim i As Int
            Dim x As Int
            th = v
           
   
            For i = 0 To th.TabCount - 1
                th.CurrentTab = i
   
                Dim r As Reflector
                r.Target = th
                Dim tabParentPanel As Panel
                tabParentPanel = r.RunMethod("getTabContentView")
       
                For x = 0 To tabParentPanel.NumberOfViews - 1
                    SetViewColors(tabParentPanel.GetView(x))
                Next       
            Next
        Case v Is Label           
            Dim lab As Label
            lab = v
            If lab.Tag="CAPTION" Then
                lab.Color=cColors.GetBG("CAPTION")
                lab.TextColor=cColors.GetFG("CAPTION")
            Else
                lab.Color=cColors.GetBG("LABEL")
                lab.TextColor=cColors.GetFG("LABEL")
            End If
        Case v Is CheckBox
            Dim chk As CheckBox
            chk = v
            chk.Color=cColors.GetBG("CHECKBOX")
            chk.TextColor=cColors.GetFG("CHECKBOX")
        Case v Is EditText
            Dim txt As EditText
            txt = v
            txt.Color=cColors.GetBG("TEXTBOX")
            txt.TextColor=cColors.GetFG("TEXTBOX")
        Case v Is RadioButton
            Dim rad As RadioButton
            rad = v
            rad.Color=cColors.GetBG("RADIOBUTTON")
            rad.TextColor=cColors.GetFG("RADIOBUTTON")
        Case v Is Button
            Dim but As Button
            but = v
            but.Color=cColors.GetBG("BUTTON")
            but.TextColor=cColors.GetFG("BUTTON")
        Case v Is Spinner
            Dim spi As Spinner
            spi = v
            spi.Color=cColors.GetBG("LISTBOX")
            spi.TextColor=cColors.GetFG("LISTBOX")
        Case v Is Panel
            Dim pnl As Panel
            pnl = v
            'pnl.Color=cColors.GetBG("BACKGROUND")
            For i = 0 To pnl.NumberOfViews - 1
                SetViewColors(pnl.GetView(i))
            Next

    End Select
 

Steve Miller

Active Member
Licensed User
Longtime User
I got it to loop through, but the speed just isn't there. It took nearly 5 minutes to loop through 13 tabs and set the foreground and background colors. Apparently, something isn't right. I checked the value of tabParentPanel.NumberOfViews in SetCustomColors, and it appears to be incrementing by 1 when it goes to the next tab.

B4X:
Sub SetCustomColors
    Dim i As Int
    If cColors.IsInitialized=False Then
        cColors.Initialize
    End If
  
    For i = 0 To TabHost1.TabCount - 1
        TabHost1.CurrentTab=i
        Dim r As Reflector
        r.Target = TabHost1
        Dim tabParentPanel As Panel
        tabParentPanel = r.RunMethod("getTabContentView")
        For x = 0 To tabParentPanel.NumberOfViews - 1
            SetViewColors(tabParentPanel.GetView(x))
        Next      
    Next

End Sub
Sub SetViewColors(v As View)

    Select Case True
        Case v Is CheckBox
            Dim chk As CheckBox
            chk = v
            chk.Color=cColors.GetBG("CHECKBOX")
            chk.TextColor=cColors.GetFG("CHECKBOX")
        Case v Is EditText
            Dim txt As EditText
            txt = v
            txt.Color=cColors.GetBG("TEXTBOX")
            txt.TextColor=cColors.GetFG("TEXTBOX")
        Case v Is RadioButton
            Dim rad As RadioButton
            rad = v
            rad.Color=cColors.GetBG("RADIOBUTTON")
            rad.TextColor=cColors.GetFG("RADIOBUTTON")
        Case v Is Button
            Dim but As Button
            but = v
            but.Color=cColors.GetBG("BUTTON")
            but.TextColor=cColors.GetFG("BUTTON")
        Case v Is Spinner
            Dim spi As Spinner
            spi = v
            spi.Color=cColors.GetBG("LISTBOX")
            spi.TextColor=cColors.GetFG("LISTBOX")
        Case v Is Panel
            Dim pnl As Panel
            pnl = v
            pnl.Color=cColors.GetBG("BACKGROUND")
            For Each v1 As View In pnl.GetAllViewsRecursive
                SetViewColors(v1)
            Next
        Case v Is Label          
            Dim lab As Label
            lab = v
            If lab.Tag="CAPTION" Then
                lab.Color=cColors.GetBG("CAPTION")
                lab.TextColor=cColors.GetFG("CAPTION")
            Else
                lab.Color=cColors.GetBG("LABEL")
                lab.TextColor=cColors.GetFG("LABEL")
            End If
    End Select
End Sub
 
Upvote 0

Steve Miller

Active Member
Licensed User
Longtime User
Lucas, that is my original post asking how to set the view colors across many layouts in a tabhost. This question was spawned from that, where I noticed that a view was both a button and label. Strange.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
A Label is an android TextView.
A Button is a sub class of TextView.
So a Button is technically both a TextView and a Button.

As suggested if you check that a View is a Button before you check that it is a Label you'll get the behaviour you expect.

Martin.
 
Upvote 0

Steve Miller

Active Member
Licensed User
Longtime User
Thanks Martin. Now, I need to figure out why it takes 5 minutes to loop through all the views on all the layouts on the tab host control.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Try:

B4X:
For x = 0 To tabParentPanel.NumberOfViews - 1
    SetViewColors(tabParentPanel.GetView(x))
    Log("Tab #"&i&" View #"&x)
Next

Do you see a sane number of Views on each tab?

Martin.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…