iOS Question Button's creation programmatically

Giusy

Active Member
Licensed User
Hi, I have to create buttons programmatically, this is the code:
B4X:
Dim x, y As Int
    For y = 0 To ROWs-1
        For x = 0 To columns - 1
            Dim bt As Button
            bt.Initialize("Button",bt.STYLE_SYSTEM) 
            strLines =list1.get(y)
            bt.Text = strLines
            bt.Tag = y*columns
            bt.CustomLabel.Font = Font.CreateNewBold(20)
            bt.CustomLabel.Font = Font.CreateNew(20)
            bt.CustomLabel.Multiline=False
            bt.CustomLabel.TextColor= Colors.RGB(0,0,128)
            bt.CustomLabel.TextAlignment = bt.CustomLabel.ALIGNMENT_LEFT
            ScreenScrollView.Panel.AddView(bt, x*BWidth,y*BHeight+2dip,BWidth,BHeight-4dip)  'Add Button
        Next
    Next
The cycle works correctly, but "ScreenScrollview.panel.addview" does not add any buttons.
Where is the error?
Thanks
 

Yvon Steinthal

Active Member
Licensed User
Longtime User
I would think it has to do with the screenscrollview's size, or it's parent.

What i do is update its inner size for each button created...

Hope it helps...
 
Upvote 0
D

Deleted member 103

Guest
B4X:
    Dim x, y As Int
    For y = 0 To ROWs-1
        For x = 0 To columns - 1
            Dim bt As Button
            bt.Initialize("Button",bt.STYLE_SYSTEM)
            strLines =list1.get(y)
            bt.Text = strLines
            bt.Tag = y*columns
            bt.CustomLabel.Font = Font.CreateNewBold(20) 'either this line
            'bt.CustomLabel.Font = Font.CreateNew(20)     'or this line
            bt.CustomLabel.Multiline=False
            bt.CustomLabel.TextColor= Colors.RGB(0,0,128)
            bt.CustomLabel.TextAlignment = bt.CustomLabel.ALIGNMENT_LEFT
            ScreenScrollView.Panel.AddView(bt, x*BWidth,y*BHeight+2dip,BWidth,BHeight-4dip)  'Add Button
            
            ScreenScrollView.Panel.Height = ScreenScrollView.Panel.Height + 1
            ScreenScrollView.ContentHeight= ScreenScrollView.Panel.Height
        Next
    Next
 
Upvote 0

Yvon Steinthal

Active Member
Licensed User
Longtime User
By default when you initialize the scrollview you initialize it's inner height, not its visible "physical" height.
The best way to troubleshoot in my opinion is to put the scrollview inside a panel of a certain height, and when you do:


B4X:
Dim pnl as Panel
pnl.initialize("")

'add the panel to your main view or whatever.

pnl.addview(ScreenScrollView,0,0,100dip,200dip) 'this is where you would set its physical visible height!

Hope it helps
 
Upvote 0

Giusy

Active Member
Licensed User
@Yvon Steinthal,
the screenscrollview is already in panel1, and even if the screenview is too small at least one button should be visible.
The program run correctly in B4A.
I do not know what to do :(
 
Upvote 0

Giusy

Active Member
Licensed User
Yes @Yvon Steinthal

B4X:
    DBWidth = 100%x-4dip
    BHeight =60dip
   
 columns=1

list1=File.readlist(File.DirAssets,"myfile.txt")
            ROWs=7

Dim x, y As Int
    For y = 0 To ROWs-1
        For x = 0 To columns - 1
            Dim bt As Button
            bt.Initialize("Button",bt.STYLE_SYSTEM) 
            strLines =list1.get(y)
            bt.Text = strLines
            bt.Tag = y*columns
            bt.CustomLabel.Font = Font.CreateNewBold(20)
            bt.CustomLabel.Font = Font.CreateNew(20)
            bt.CustomLabel.Multiline=False
            bt.CustomLabel.TextColor= Colors.RGB(0,0,128)
            bt.CustomLabel.TextAlignment = bt.CustomLabel.ALIGNMENT_LEFT
            ScreenScrollView.Panel.AddView(bt, x*BWidth,y*BHeight+2dip,BWidth,BHeight-4dip)  'Add Button
        Next
    Next

In strLines the text is read correctly
 
Upvote 0

Giusy

Active Member
Licensed User
Yes
 

Attachments

  • SCROLLO.PNG
    SCROLLO.PNG
    8.5 KB · Views: 243
Upvote 0

Yvon Steinthal

Active Member
Licensed User
Longtime User
Ah you're using the designer.
I suggest setting a color to the scrollview to check if its at least there!
Verify as well that in the scrollview's properties, its parent is Panel1.
 
Upvote 0

Yvon Steinthal

Active Member
Licensed User
Longtime User
Numerous troubleshooting can be done at this point, is the parent panel visible? to check change the color to blue, and change the scrollview's color to red.
The first step is to actually figure out if you can at least see it without even adding buttons to it...
 
Upvote 0

Giusy

Active Member
Licensed User
Yes, I had just done this.

Panel1 white, screenscrollview blue
All the screen is white.
I have write screenscrollview.bringtofront... but nothing
 
Upvote 0

Giusy

Active Member
Licensed User
@Yvon Steinthal
I have resolved the gray part with content width = 0 in screenscrollview properties.

I found that unlike b4a, the positioning values between one button and the other are not increased.

I think that, working a little, I will succeed in winning my battle

I thank you for having dedicated all this time, you have been very kind :)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The most efficient way to solve your problem would have been to post a test project showing the problem.
That way we could have a look at all your code and most important test it in the same conditions as you do.
 
Upvote 0
Top