Msgbox(Activity.numberofViews,"") displays wrong number

Mahares

Expert
Licensed User
Longtime User
I have a project with no tabhost. When I issue Msgbox(Activity.numberofViews,"") , it displays the correct number, say: 27. I have another project that has one tabhost and several views, when I issue Msgbox(Activity.numberofViews), it displays 1 which is not correct. How can I get the correct number of views in the project which has a tabhost?
Thank you
 

Mahares

Expert
Licensed User
Longtime User
The project has 1 Activity , 1 Tabhost. The tabhost has 2 pages with 2 separate layouts. Each page has several views (edittext, labels, buttons). They are all added via the designer and are all part of the same activity as a parent. If you test the TabHost.b4a sample you supply, you will see the same phenomenon happening. I am not sure what you mean by your following statement:
Activity.NumberOfViews returns the number of views that were added directly to the activity. It will not show other views.
Below is an excerpt of my code:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("LayoutMain")
Activity.Title="GAS FLOW CALCULATIONS & PLATE SIZE SELECTION"
TabHost1.AddTab("MCFD CALCULATION", "LayoutOrifice")
TabHost1.AddTab("PLATE SIZE SELECTION", "LayoutPlate")
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The propblem is that in the project with one TabHost in the activity, the activity has only 1 view the TabHost, all the other views belong to the TabHost panels. Unfortunately it is impossible (yet Erel ?) to get the views of a TabHost directly in B4A.
The same would happen if you had an Activity with one Panel containing several other views, the number of views of the Activity is 1, all the other belong to the Panel. But in this case you can get the number views of the Panel.

Best regards.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If the tabhost controls the views then in this case you will not be able to control the same action of a group of views like showing or hiding programmatically. In other words you cannot programmatically perform the following:
Dim i As Int
Dim v As View
For i=0 To Activity.NumberOfViews-1
v=Activity.GetView(i)
v.visible=False
.....
Next

You have to do it individually like: Item1.visible=False, etc.
Thank you.
 
Upvote 0
Top