Panels vs Layouts

noclass1980

Active Member
Licensed User
Longtime User
Hi, this is my first post so apologies for asking a basic question. I found Basic4Android just last week and think it is just fantastic, very easy to use and understand as I have a VB background rather than Jarva. Thank you for opening Anroid application dev to me!
Anyway back to the point. I want to make an app that starts with the Main layout with labels and buttons etc. When a button is pressed, I want to display another layout (say Layout1) with different labels etc.
1) should the new layout be a new Activity that is called when the button is pressed on the Main layout?
2) Do I need a Panel on the new layout to hold all the labels etc together or is this achieved by having separate layouts?
3) if the new layout is in a new Activity then presumably all the views on Layout1 need to be initialsed via the usual Activity_Create(FirstTime as Boolean).
Thanks, any help much appreciated to get me started!
 

barx

Well-Known Member
Licensed User
Longtime User
Hi and welcome.

1) the choice is your really, different tasks suit the different methods. Personally I prefer to use separate activities, the next person along could prefer swapping out / popping up panels.

2) again your choice. You don't 'need' a panel to hold the views (labels, etc) the activity itself can happily hold them. Having a holding panel can come in useful though for hiding a group of view at once or moving them.

3) if you are using layouts built using the designer then you do not need to initialize the views. Just declare them in the globals section. e.g.

B4X:
Dim lblName as Label

Note: the names used in the declarations must match those in the layout.

Hope this helps.
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
Thanks, that helps. Guess its just a case of suck it and see. I'm finding the Beginners guide and the numerous tutorials very helpful. If I understand your answer to 3), using the Designer and Generating Members then declares the variables as you show but if I use code to create a view with panel1.Addview(label1) etc then I need to have initialised it first with label1.Initialize(""). Is that correct? Thanks
 
Upvote 0
Top