B4J Question B4XFloatTextField

Status
Not open for further replies.

GianniGntl

Member
Licensed User
How to add a B4XFloatTextField to a panel and initialize it in code ?

It is discouraged to add controls programmatically, but if you really need you can try my approach.
The first FloatTextField is added with the designer, the second programmatically.
You can omit the former and set the values in the latter directly, via mBase and lbl.

B4XMainPage.bas:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private B4XFloatTextField1 As B4XFloatTextField
    Private B4XFloatTextField2 As B4XFloatTextField
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Sleep(1)
    Root.LoadLayout("MainPage")
    Sleep(1)
    
    Dim base As B4XView = xui.CreatePanel("Panel2")
    
    ' Copying dimension and position from first control, positioning second one below, w/o overlapping
    Dim heigth As Int = B4XFloatTextField1.mBase.Height
    Root.AddView(base, B4XFloatTextField1.mBase.Left, B4XFloatTextField1.mBase.Top + heigth +10dip, B4XFloatTextField1.mBase.Width, heigth)
    
    ' Copying textfield visual properties from first control
    Dim lbl As B4XView = XUIViewsUtils.CreateLabel
    lbl.TextColor = B4XFloatTextField1.TextField.TextColor
    lbl.Font = B4XFloatTextField1.TextField.Font
    
    B4XFloatTextField2.Initialize(Me, "B4XFloatTextField2")
    B4XFloatTextField2.DesignerCreateView(base, lbl, CreateMap("Hint":"Surname", "HintColor": 0xFF008EFF, "NonFocusedHintColor": 0xFF393939))
    
End Sub
 
Upvote 0
Status
Not open for further replies.
Top