B4J Question [SOLVED] The case of the width of a TextField - (title of a crime movie 😁)

LucaMs

Expert
Licensed User
Longtime User
(I don't remember how to add an emoji to the title! :( )


In a class I have:

B4X:
Public Sub Initialize(PlusMinus As B4XPlusMinus)
    mPlusMinus = PlusMinus
  
    Dim mBase As B4XView = PlusMinus.mBase
    mPnlOver.Initialize("pnlOver")
  
    mBase.AddView(mPnlOver, PlusMinus.pnlMinus.Width, 0, PlusMinus.mBase.Width - PlusMinus.pnlMinus.Width - PlusMinus.pnlPlus.Width, PlusMinus.MainLabel.Height)
        Log("mPnlOver.width: " & mPnlOver.Width)

That log in B4A is 445, in B4J 0 (zero!)
So mPnlOver width is wrong, in B4J.


(enough infos?)


EDIT: The B4XPlusMinus that I pass to that initialization is in a layout that I load into the B4XMainPage (Root, of course).
 

LucaMs

Expert
Licensed User
Longtime User
I guess that the page wasn't resized yet. You need to handle the resize event.
Most likely you are right (as always!) but doing that makes the creation of the object anomalous for the programmer.

BTW, I tried a Sleep (not directly in Initialize, which can't accept it, but in a Sub called by Initialize - CallSubDelayed) but it failed (maybe too short duration? I'll try again).


I think the simplest solution is to attach the project; this way you, Erel, will finally have something to occupy your too much free time 😁
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I solved it, albeit not in a very orthodox way.

B4X:
Public Sub Initialize(PlusMinus As B4XPlusMinus)
    mPlusMinus = PlusMinus
   
    mPnlOver.Initialize("pnlOver")
    'Initialize cannot be a resumable, so...
    CallSubDelayed2(Me, "Init2", PlusMinus)
End Sub

Private Sub Init2(PlusMinus As B4XPlusMinus)
    PlusMinus.mBase.AddView(mPnlOver, PlusMinus.pnlMinus.Width, 0, PlusMinus.mBase.Width - PlusMinus.pnlMinus.Width - PlusMinus.pnlPlus.Width, PlusMinus.MainLabel.Height)
    Do Until mPnlOver.Width > 50
        Sleep(1)
    Loop

(that 50 is an arbitrary value!)
 
Upvote 0
Top