Android Question Help with Designer

Alisson

Active Member
Licensed User
Hi!!!

I can create an interface in Visual Designer, then extract the code for B4A ?

I created a simple interface in the Visual Designer , now want to extract the code automatically of the interface, positions of components.
Is possible?

Thank you very much
 

Attachments

  • VisualDesigner.png
    53.7 KB · Views: 171

eurojam

Well-Known Member
Licensed User
Longtime User
I am not shure, if I understand your question: if you want to get the position of the views, it is just something like this one:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
  
    For Each v As View In Activity.GetAllViewsRecursive
        Dim ref As Reflector 'get the class; this is not necessary
        ref.Target = v  'this is not necessary
        Log(ref.RunMethod("getClass"))  'this is not necessary
        'get the position
        Log("Left " & v.left & " Top " & v.Top & " Width " & v.Width & " Height " & v.Height)
    Next

End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is not the correct way to get the type.

The correct way is with:
B4X:
If v Is Label Then
 Dim lbl As Label = v
End If
This code will also handle all views that are subclasses of label (button, checkbox and others). In most cases it is good as you can treat many views with the same code.

If you want to get the exact type:
B4X:
Log(GetTYpe(v))

With that said, the visual designer is very powerful. Almost everything that can be done with code is simpler to implement with anchors and designer script.
 
Upvote 0

Alisson

Active Member
Licensed User
Erel, my project needs to http request.
The answer assembles the design of the interface.
A label may or may not exist in a http response .
Do you think this inappropriate my procedure?
 

Attachments

  • screen.png
    24.8 KB · Views: 154
Upvote 0

Alisson

Active Member
Licensed User
DonManfred , I read your post, but I have some questions that will help to develop , I think 90 % of my apps.
In my desinger I have the Labels , ImagesView , Panel among others.
In my code I have :

B4X:
Activity.LoadLayout("1")
Label1.Initialize("Label1") 
Label1.Text = "Hello world"

When I started the label and passed a value , my application stopped and did not change in my interface designer .
When you say leave the Label inivisível is like:
B4X:
panel.visible = true
?
Thank you for your help.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
you should NOT initialize views added in the designer!!!!!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…