Android Question Can i change StdActionBar tab name in runtime?

dragonguy

Active Member
Licensed User
Longtime User
anyone know how to change StdActionBar tab name in runtime?
my application start will auto add three tab with name "Tab1","Tab 2","Tab 3" then after 60 second tab auto change "Tab 1" to "ABC", "Tab 2" to "DEF", "Tab 3" to "123".
Is it possible to do that?
 

eurojam

Well-Known Member
Licensed User
Longtime User
yes it is, you have to remove the tabs and then add them again....see small example:
B4X:
Sub Globals
    Dim bar As StdActionBar
    Private vp As StdViewPager
    Private timer1 As Timer
    Dim isNum As Boolean
  
End Sub

Sub Activity_Create(FirstTime As Boolean)  

    bar.Initialize("bar")
    bar.AddTab("1")
    bar.AddTab("2")
    bar.AddTab("3")
    bar.NavigationMode = bar.NAVIGATION_MODE_TABS
    Dim height As Int = CalculateHeight(True, True)
    vp.Initialize("vp",3, 100%x, height)
    Activity.AddView(vp.AsView, 0, 0, 100%x, height)
  
    timer1.Initialize("timer1",1000)
    timer1.Enabled=True          
    isNum = True
End Sub

Sub timer1_tick
    bar.RemoveTabs
    If isNum = True Then
        bar.AddTab("ABC")
        bar.AddTab("DEF")
        bar.AddTab("GHI")
    Else
        bar.AddTab("1")
        bar.AddTab("2")
        bar.AddTab("3")       
    End If      
    isNum = Not(isNum)
End Sub


Sub CalculateHeight (TabsMode As Boolean, SplitEnabled As Boolean) As Int
    If 100%x >= 480dip Then
        Return 100%y
    Else
        Dim fix As Int
        If TabsMode Then fix = 48dip
        If SplitEnabled Then fix = fix + 48dip
        Return 100%y - fix
    End If
End Sub
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
see below
B4X:
ub Process_Globals

End Sub

Sub Globals
    Dim bar As StdActionBar
    Private vp As StdViewPager
    Private timer1 As Timer
    Dim isNum As Boolean
    Dim st As Int
   
End Sub

Sub Activity_Create(FirstTime As Boolean)   

    bar.Initialize("bar")
    bar.AddTab("1")
    bar.AddTab("2")
    bar.AddTab("3")
    bar.NavigationMode = bar.NAVIGATION_MODE_TABS
    Dim height As Int = CalculateHeight(True, True)
    vp.Initialize("vp",3, 100%x, height)
    Activity.AddView(vp.AsView, 0, 0, 100%x, height)
   
    timer1.Initialize("timer1",1000)
    timer1.Enabled=True           
    isNum = True

End Sub

Sub bar_TabChanged(Index As Int, STab As StdTab)
    st = Index
End Sub

Sub timer1_tick
    bar.RemoveTabs
    If isNum = True Then
        bar.AddTab("ABC")
        bar.AddTab("DEF")
        bar.AddTab("GHJ")
    Else
        bar.AddTab("1")
        bar.AddTab("2")
        bar.AddTab("3")        
    End If       
    isNum = Not(isNum)
    bar.SelectedIndex = st
End Sub

Sub CalculateHeight (TabsMode As Boolean, SplitEnabled As Boolean) As Int
    If 100%x >= 480dip Then
        Return 100%y
    Else
        Dim fix As Int
        If TabsMode Then fix = 48dip
        If SplitEnabled Then fix = fix + 48dip
        Return 100%y - fix
    End If
End Sub
 
Upvote 0
Top