Android Question Using a Layout created in the Designer and Adding Views in code

JaunLukePicard

Member
Licensed User
Longtime User
I am finding that it is MUCH easier to create a layout and load it in the Activity as opposed to writing a tone of code depending on how many Views that are on a particular screen.

If, for example, I have a standard Designer layout I have built, but want to add some custom views to it before it is shown to the user what are the steps to do this in B4A?

In this case I have a class that creates a ScrollView2d Table. The layout I have built has the buttons I want to display for the layout. I am doing it this way because I may use the ScrollView2d several times for different tables.
So I thought of doing the following in code which would create the Panel, show the table via ScrollView2d and then load the layout to show the buttons.

Here is the section of code I have...

B4X:
pnlTable.Initialize("pnlTable")
Activity.AddView(pnlTable, 20dip, 20dip, 100%x - 40dip, 100%y - 90dip)   
pnlTable.LoadLayout("scnMain")

What I end up with is the table only without the buttons at the bottom.
 

JaunLukePicard

Member
Licensed User
Longtime User
Earl,

Yes you are correct. I just figured it out. Sometimes we think that things are harder then they really are.

Attached ut the code that worked...
B4X:
pnlTable.Initialize("")
Activity.LoadLayout("scnMain")
Activity.AddView(pnlTable, 20dip, 20dip, 100%x - 40dip, 100%y - 90dip)
 
Upvote 0
Top