My target is have a SegmentedControl on the top of a layout with 4 Items. And for each Item charge a layout. My question is, Do I need have a SegmentedControl on the 4 layouts? or Can I have a only SegmentedControl and work with panels?
For example:
B4X:
SC as segmentedcontrol
Sub SC_IndexChanged (Index As Int)
select index
case 0:
panel1.visible=true
panel2.visible=false
panel3.visible=false
panel4.visible=false
case 1:
panel1.visible=false
panel2.visible=true
panel3.visible=false
panel4.visible=false
case 2:
.
.
.
case 3:
.
.
.
end select
end Sub
In my opinion work with panel for this target is not the best option, because all the app have only a layout, but I dont know how can I do this with layouts.
Consider using TabHostController instead. This is the more natural solution.
With a segmented control you have two options:
1. Use multiple panels.
2. Use multiple pages with multiple segmented controls.
Always try to avoid duplicating code.
You can do something like:
B4X:
Dim panels() As Panel = Array As Panel(panel1, panel2, panel3, panel4)
...
'then you can easily change panels:
'change to panel i (0 - 3):
For x = 0 to panels.Length - 1
panels(i).visible = x = i
Next
'or more "standard":
If x = i Then panels(i).Visible = True else panels(i).Visible = False