Android Question How do I get a Tabhost tab title

JamesGreaves

Active Member
Licensed User
How do I GET a Tabhost tab Title? I've tried numerous angles, it seams impossible...is it?

I hoped for something as simple as: TabTitle = TabHost1.Get(0).Title

But I want to get all the Tab Titles in all the TabHost's.

So I've got this so far:

Dim ThisTab As TabHost
Dim TabTitle As String

For Each t As TabHost In Activity.GetAllViewsRecursive

ThisTab = t

For Each tt As TabHost.tab In ThisTab

TabTitle = tt.Title
Msgbox(TabTitle)

Next

Next
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

For Each t As TabHost In Activity.GetAllViewsRecursive
This line is wrong. Activity.GetAllViewsRecursive returns all the views not just the tab hosts.

There is no simple way to directly get the tabs titles. You can do something like:
B4X:
Sub AddTab(th As TabHost, Title As String, LayoutFile As String)
 Dim titles As List
 If th.Tag = "" Then
   titles.Initialize
    th.Tag = titles
 End If
 titles = th.Tag
 titles.Add(Title)
 th.AddTab(Title, LayoutFile)
End Sub

'Now you can get all titles with:
For Each v As View In Activity.GetAllViewsRecursive
 If v Is TabHost Then
  Dim titles As List = v.Tag
  Log(titles)
 End If
Next
 
Upvote 0
Top