Android Question Tabhost with two identical Layoutfiles

Michael Müller Anywhere

Licensed User
Longtime User

I have a tabhost with 6 Layoutfiles.
Two of them has the same name (in this case: Page_2)

But only the second tab with "Page 2" will be shown.
The first tab with Page_2 is empty.

Tabhost code:
    TabHost1.AddTabWithIcon ("", bmp1a, bmp1, "Page_1")
    TabHost1.AddTabWithIcon ("",  bmp5a, bmp5, "Page_2")     
    TabHost1.AddTabWithIcon ("",  bmp6a, bmp6, "Page_2")     
    TabHost1.AddTabWithIcon ("",  bmp2a, bmp2, "Page_3")     
    TabHost1.AddTabWithIcon ("",  bmp4a, bmp4, "Page_4")
    TabHost1.AddTabWithIcon ("" ,  bmp3a, bmp3, "Page_5")

The reason I need two identical Layoutfiles (Page_2) is that there are many views (150) in it.
With the next code I can make some views visible/invisible

sub TabHost1_TabChanged
    Select Case TabHost1.CurrentTab
        Case 0
        Case 1, 2
            'my code to to make some views visible/invisible
    end select
end sub

Is there a way to use 2 identical Layoutfiles without copy all views and put them in a new file with another name?


Well-Known Member
Licensed User
Longtime User
Whilst not a direct answer to your question ...

Is it not an option to load / display all the views in a ScrollView and present that in Tab 2 .. allowing the user to scroll thru all the views ?
Upvote 0

Michael Müller Anywhere

Licensed User
Longtime User
Thank you,

but the place is no problem because there a buttons for submenues in both files.

My project is an inputmask on a tablet for 2 different rescue-szenarios (2 menues)
the first Page_2 is for input the information of the place and person (big rescue szenario)
the second Page_2 is only for input the information of the person (another rescue szenario)
In this second szenario I make a button "place" invisible. The input-mask for the person is the same.
Upvote 0


B4X founder
Staff member
Licensed User
Longtime User
Tip: TabHost is quite an outdated control. In most cases it is better to use TabStripViewPager.

You can load layouts multiple times.

A global view variable will point to the last view loaded with the relevant name. This means that you need to use a different way to access the views.
There are many ways to do it. A simple one is to access them based on the indices.

Another option is to fill a Map with the views that you need to access, right after you loaded the layout.
Upvote 0