Android Question Tabhost and loading page layouts in B4A version 3.82

kobewarui

Member
Licensed User
Longtime User
Hi am new to B4A and am using version 3.82.My problem is am trying to load the layout pages that i saved in the designer to each tab that i have created.I have successfully designed a tab with 5 tabs on it using the tabhost.The problem is the pages that i intend to display on each tab are not showing even though i have followed every example in the online help and in the beginners guide.Kindly assisst as this would of great help.My code is as below:

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Dim TabHost1 As TabHost
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("home_page")
TabHost1.AddTab("Music","music")
TabHost1.AddTab("Recoder","recoder.bal")
TabHost1.AddTab("Chat","chat")
TabHost1.AddTab("Messages","sign_up")
TabHost1.AddTab("s", "search"

music,recoder,chat,sign_up,search are layout pages made in the designer but i have not generated members of each layout yet.I dont know if this could be a problem

I have also tried using a panel as shown in the beginners guide but the panels/layout pages are not showing once i run the program.the code is as below:

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim music,recoder,messages,chat,search As Panel
Dim TabHost1 As TabHost
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("home_page")
TabHost1.AddTab("Music","music")
TabHost1.AddTab("Recoder","recoder")
TabHost1.AddTab("Chat","chat")
TabHost1.AddTab("Messages","messages")
TabHost1.AddTab("s", "search")

the panel variables show a warning that the variables declared in the panel are never used
 

eps

Expert
Licensed User
Longtime User
Where do you add Tabhost1 to the Activity? How is Layout1 defined? In the Designer or by hand?

N.B. please use [ code ] and [/ code ] tags to make the code more readable.
 
Upvote 0

kobewarui

Member
Licensed User
Longtime User
HI sorry about the unreadability of the code.I created a project and added modules to it.I have an activity module defined by the following line of code:
B4X:
Activity.LoadLayout("home_page")
.I designed it in the designer and saved it.I also created this other layout files in the designer"music,chat,messages,recoder,search" and i wanted to display each of these layout files on each tab but after i run the program the tabs are there but the layout pages are not there.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Have you checked in the designer to ensure that the Layout panels are of the correct size, etc..?

I use :

B4X:
    TabHost1.AddTabWithIcon("All", bmp1, bmp2, "page1.bal") 'load the layout file of each page
    TabHost1.AddTabWithIcon("Series", bmp3, bmp4, "page2.bal")
    TabHost1.AddTabWithIcon("Favourites", bmp5, bmp6, "page3.bal")
    TabHost1.AddTabWithIcon("Options", bmp7, bmp8, "page4.bal")

The pages are created in the designer... but I resize them using code, so that they occupy all of the space available and have the relevant elements placed in them, i.e. ListView, Panel, etc... So they're all bal files, created in the designer or somewhere..
 
Upvote 0

kobewarui

Member
Licensed User
Longtime User
can i take a screenshot from the emulator ? if so how do i do it ?.Okay let me ask how do i work with a tabhost ? i want to create an activity lets say activity main with 5 tabs on the top of the page.what i now want to achieve but i havent is "i want each tab to display a different activity when you click on any tab but still being on the same activity i.e main " in simple words how does the tabhost work ? i have tried all the exmaples in the online community but still havent achieved that.I must be doing something wrong.
 
Upvote 0

kobewarui

Member
Licensed User
Longtime User
B4X:
Activity.LoadLayout("home_page")
TabHost1.AddTab("Music","music.bal")
TabHost1.AddTab("Recoder","recoder.bal")
TabHost1.AddTab("Chat","chat.bal")
TabHost1.AddTab("Messages","messages.bal")
TabHost1.AddTab("s", "search.bal")

i did the same thing as above but the pages i designed in the designer do not show and that the problem am having.Do i have to use the extension .bal ?
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
No ... .bal extension is not necessary.

I'm thinking tabhost1 on the "home_page" layout not sized correctly...

maybe try ..
B4X:
Sub Activity_Create(FirstTime As Boolean)

'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")

'Activity.LoadLayout("home_page")
TabHost1.Initialize("tabhost1")
Activity.AddView(TabHost1,0,0,100%x,100%y)

TabHost1.AddTab("Music","music")
TabHost1.AddTab("Recoder","recoder.bal")
TabHost1.AddTab("Chat","chat")
TabHost1.AddTab("Messages","sign_up")
TabHost1.AddTab("s", "search")
'..................
 
Last edited:
Upvote 0

kobewarui

Member
Licensed User
Longtime User
mj,thank you so much it worked.I had to delete the tab host that i dragged and dropped in the designer and use the code you gave me above to create one programmatically.

Thanks to you eps for the assistance too really appreciate it.
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
your welcome ..;)
 
Upvote 0
Top