Build layout with XML

balistreri1

Member
Licensed User
Longtime User
I am interested in generating layout files without the designer..
or
I would like to load into a Basic4Android APP a standard XML layout file
generated automatically by a web based method that writes text files.

If there is another way,please help.

My goal is to create layouts with on a website and generate an XML
or BAL file that will be loaded by a Basic4Android APP..
 

warwound

Expert
Licensed User
Longtime User
You can load XML layouts if you create a Java based library but not directly from B4A.

Layout files (set as read only) in your project's Objects\res\layout folder are compiled into your project and accessible via Java using a String identifier.

BUT an XML layout file downloaded at runtime will not be so 'easily' accessible.
It won't be compiled into the project and not accessible by a String identifier from Java.

The native Android LayoutInflater class is what you might be able to use to dynamically create a layout from a downloaded XML file.

I'm not sure if what you want to do is possible even in a library - a search on Google shows a few similar questions so i'd say take a look at the LayoutInflater class and google for possible code examples.

Martin.
 
Upvote 0

balistreri1

Member
Licensed User
Longtime User
Thanks warwound,

I can also load the layout attributes from a SQL DB or a MAP file, however, it seems alot more practical to simply modify the layout. LoadLayout, versus a whole series of loading button attributes...
 
Upvote 0

balistreri1

Member
Licensed User
Longtime User
Thanks Erel,

Regarding a data file, are you referring to the map file method?
That does work, I have been using it so far.

However, I am not sure where the resulting MAP file is saved to. After I compile and run
it on the emulator, I check the project folders, and I do not see it. Do you know how I can declare this MAP file name and location?

Sub Activity_Create(FirstTime As Boolean)
' Save Button attributes
Map1.Initialize
Map1.Put("B1_Text", "Hello World" )
Map1.Put("B1_Width", 150 )
Map1.Put("B1_Height", 150 )
Map1.Put("B1_Left", 50 )
Map1.Put("B1_Top", 50 )
Map1.Put("B1_Enabled", True )
Map1.Put("B1_Visible", True )
Map1.Put("B1_Text_Size", 20 )
Map1.Put("B1_Text_Color", Colors.Yellow )
Map1.Put("B1_Color", Colors.Blue )
Map1.Put("B1_Bitmap_Enable", False )
Map1.Put("B1_Bitmap_File", "75x75_grey.PNG" )
Activity.LoadLayout("Layout1")
' Go to set button attributes

Set_Button1_State

End Sub

Sub Set_Button1_State

' Get Button1 ENABLED STATE
' If Button1 is ENABLED then load settings
If Map1.Get("B1_Enabled") = True Then
Button1.Text = Map1.Get("B1_Text")
Button1.Enabled = Map1.Get("B1_Enabled")
Button1.Visible = Map1.Get("B1_Visible")
Button1.TextSize = Map1.Get("B1_Text_Size")
Button1.Height = Map1.Get("B1_Height")
Button1.Width = Map1.Get("B1_Width")
Button1.Top = Map1.Get("B1_Top")
Button1.Left = Map1.Get("B1_Left")
If Map1.Get("B1_Bitmap_Enable") = True Then
Button1.SetBackgroundImage(LoadBitmap(File.DirAssets, Map1.Get("B1_Bitmap_File")))

Else
Button1.TextColor = Map1.Get("B1_Text_Color")
Button1.Color = Map1.Get("B1_Color")
End If

Else
' Button1 DISABLED Warn USER
Msgbox("WARNING", "Button1 DISABLED")
End If

End Sub
 
Upvote 0
Top