change object properties from a code module

EddyW

Member
Licensed User
Longtime User
I am new to B4A but have experience in VB6.

I am busy with a project that will have about 25 screen's/activity and several modules and i have a question about this. I am looking for a way to easy change the settings of the object on the screen and not each time to open all layouts and change the settings manually.

What i want but dont know if possible is to have a 'code module' that handles every object setting like color, textsize and textcolor.
Each object will have a tag and based on the tag the object will be set.

in each Activity_Create i will call that module.
something like this (not real code)
screen 1, Activity_Create, call module.SetObjectSettings(me)
screen 2, Activity_Create, call module.SetObjectSettings(me)

module.SetObjectSetting(screen)
for each object in Screen
select case object.tag
case "layout1"
object.color= colors.red
object.textsize = 12
case "layout2"
object.colors = colors.green
object.textsize =10
case else

end select
next

is this possible and if so how i do this?
 

EddyW

Member
Licensed User
Longtime User
i made a function that accept a activity and loop thru the views on that activity to change the color, textsize and textcolor.

It works but now i have on 1 activity a tabhost with 3 tabs that each has some views that i want to change too.

How can i change the views that are placed 'inside' a tabhost?
 
Upvote 0

EddyW

Member
Licensed User
Longtime User
i made the code below to loop thru the views on a tab/panel but it dont work.
Can anyone see why it dont work?
I cant upload the project but below is the code goes wrong.
Somehow the else if the lowest code dont see the views on the panel/tab

This is the code for the forms
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("layTabs")

   Tabs.AddTab("Selecteer DP/Adres", "laySelecteerDP")
   Tabs.AddTab("Afspraken", "layAfspraken")
   Tabs.AddTab("Status AP", "layToonStatusAP")
   Tabs.AddTab("Offline Werken", "laySelecteerOffline")
      
   TabAfspraken
   TabSelecteerDP   
   
   Scherm.ChangeLayout(Activity) '<== this is the function that dont work
   
End Sub
Sub TabAfspraken 
   tAfspraken.Initialize(Me, "tAfspraken", 9)
   pAfspraken.Color = Colors.Transparent
   tAfspraken.AddToPanel(pAfspraken, 0, 0, 88%x, 100%y - 100)
   tAfspraken.SetHeader(Array As String("x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9"))   
   DBUtils.ExecuteTableView(DB.SqlDB, "SELECT x1, x2, x3, x4, x5, x6, x7, x8, x9 FROM Afspraken", Null, 0, tAfspraken)
End Sub

Sub TabSelecteerDP
   DBUtils.ExecuteSpinner(DB.SqlDB, "SELECT DP FROM DPs WHERE AP = '" & WebService.gsActieveAP &"'", Null, 0, cboSelecteerDP, "<Selecteer DP>")
   DBUtils.ExecuteSpinner(DB.SqlDB, "SELECT Straat FROM Straten WHERE AP = '" & WebService.gsActieveAP &"'", Null, 0, cboStraat, "<Selecteer Straat>")   
End Sub

this is the code that dont work for tabs/panels
B4X:
Sub Process_Globals

   Private iButtonKleur As Int = Colors.LightGray
   Private iButtonTekstKleur As Int = Colors.Black
   Private iButtonTekstGrote As Int = 20
   
   Private iTekstKleur As Int = Colors.LightGray
   Private iTekstGrote As Int = 18

End Sub

Sub ChangeLayout(Scherm As Activity)
   Dim iCount As Int
   
   For iCount = 0 To (Scherm.NumberOfViews -1)               
      'ToastMessageShow(GetType(Scherm.GetView(iCount)),True)   
      If Scherm.GetView(iCount) Is CheckBox Then
         Dim Obj1 As CheckBox
         Obj1 = Scherm.GetView(iCount)
         Obj1.Color = Colors.Transparent
         Obj1.TextSize = iTekstGrote
         Obj1.TextColor = iTekstKleur
      Else If Scherm.GetView(iCount)Is Button Then   
         Dim Obj2 As Button
         Obj2 = Scherm.GetView(iCount)
         Obj2.Color = iButtonKleur
         Obj2.TextSize = iButtonTekstGrote
         Obj2.TextColor = iButtonTekstKleur
      Else If Scherm.GetView(iCount)Is EditText Then   
         Dim Obj3 As EditText
         Obj3 = Scherm.GetView(iCount)
         Obj3.TextSize = iTekstGrote
         Obj3.TextColor = iTekstKleur   
      Else If Scherm.GetView(iCount)Is Spinner Then
         Dim Obj4 As Spinner
         Obj4 = Scherm.GetView(iCount)
         Obj4.TextSize = iTekstGrote
         Obj4.TextColor = iTekstKleur      
      Else If Scherm.GetView(iCount)Is Label Then
         Dim Obj5 As Label
         Obj5 = Scherm.GetView(iCount)
         Obj5.TextSize = iTekstGrote
         Obj5.TextColor = iTekstKleur
      Else If Scherm.GetView(iCount) Is CheckBox Then
         Dim Obj6 As CheckBox
         Obj6 = Scherm.GetView(iCount)
         Obj6.Color = Colors.Transparent
         Obj6.TextSize = iTekstGrote
         Obj6.TextColor = iTekstKleur
      Else If Scherm.GetView(iCount) Is TabHost Then '<== this else if dont work
         'TODO load controls van tab
         Dim obj7 As TabHost
         obj7 = Scherm.GetView(iCount)

         For i = 0 To obj7.TabCount - 1
            Dim ref As Reflector
            Dim tabParentPanel As Panel
            
            obj7.CurrentTab = i
            
            ref.Target = obj7
            tabParentPanel = ref.RunMethod("getTabContentView")
            
            Log ("Tab: " & i & " - Views : "& tabParentPanel.NumberOfViews)
            
            For j = 0 To tabParentPanel.NumberOfViews - 1
               ChangeTabHost(tabParentPanel.GetView(j)   )
            Next
         Next
         obj7.CurrentTab=0
      End If      
   Next

End Sub

Sub ChangeTabHost(VControl As View)
   
   Log ("ChangeTabHost: " & GetType(VControl))
               
   If VControl Is CheckBox Then
      Dim Obj1 As CheckBox
      Obj1 = VControl
      Obj1.Color = Colors.Transparent
      Obj1.TextSize = iTekstGrote
      Obj1.TextColor = iTekstKleur
   Else If VControl Is Button Then   
      Dim Obj2 As Button
      Obj2 = VControl
      Obj2.Color = iButtonKleur
      Obj2.TextSize = iButtonTekstGrote
      Obj2.TextColor = iButtonTekstKleur
   Else If VControl Is EditText Then   
      Dim Obj3 As EditText
      Obj3 = VControl
      Obj3.TextSize = iTekstGrote
      Obj3.TextColor = iTekstKleur   
   Else If VControl Is Spinner Then
      Dim Obj4 As Spinner
      Obj4 = VControl
      Obj4.TextSize = iTekstGrote
      Obj4.TextColor = iTekstKleur      
   Else If VControl Is Label Then
      Dim Obj5 As Label
      Obj5 = VControl
      Obj5.TextSize = iTekstGrote
      Obj5.TextColor = iTekstKleur
   Else If VControl Is CheckBox Then
      Dim Obj6 As CheckBox
      Obj6 = VControl
      Obj6.Color = Colors.Transparent
      Obj6.TextSize = iTekstGrote
      Obj6.TextColor = iTekstKleur      
   End If      

End Sub
 
Upvote 0

EddyW

Member
Licensed User
Longtime User
i found it had to go 1 level deeper then i did.

tabParentPanel isnt the panel i thought it was but holds the panels i was looking for.
 
Upvote 0
Top