iOS Question Scrollview only shows last item in list

DickD

Active Member
Licensed User
I'm porting my app from B4A to B4I. In B4A The code shown below works to display all the items in an array in a scrollview. In B4I only the last item displays (in it's proper location at the bottom of the scrollview). The log shows that the loop is running and that there is text in each of the llabel labels. I have tried setting the scrollview to .visible or .bringtofront or .requestfocus but nothing works. Also experimented with dips which I guess I don't need in B4I.

B4X:
Sub Start
PF.Initialize("PF")
PF.RootPanel.LoadLayout("ProfileLayout")
scv1.Panel.LoadLayout("PFPanel")
scv1.ContentHeight = Panel1.Height
scv1.ContentWidth = scv1.Width
Main.NavControl.ShowPage(PF)
End Sub

Sub LoadLayout
Dim llabel As Label
Dim Row As Int = 1
Dim ScrollPosition As Int = 0
llabel.Initialize("llabel")
qname.text = "Q1 of " & QuestionArray.NumberOfQuestions & ": " & QuestionArray.Question(Row,0)
For x = 1 To QuestionArray.ButtonsPerQuestion(Row)
llabel.text = QuestionArray.Question(Row,x)
Log("x = " & x & " llabel = " & llabel.text)
scv1.Panel.AddView(llabel,10, ScrollPosition, 110, 50)
ScrollPosition = ScrollPosition+40
Next
End Sub
 

klaus

Expert
Licensed User
Longtime User
Where do you call LoadLayout?
You should move
Dim llabel AsLabel
inside the For / Next Loop!
B4X:
Sub LoadLayout
    Dim llabel AsLabelDim Row As Int = 1
    Dim ScrollPosition As Int = 0
    llabel.Initialize("llabel")
    qname.text = "Q1 of " &      QuestionArray.NumberOfQuestions & ": " & QuestionArray.Question(Row,0)
    For x = 1To QuestionArray.ButtonsPerQuestion(Row)
        llabel.text = QuestionArray.Question(Row,x)

should be:
B4X:
Sub LoadLayout
    Dim Row As Int = 1
    For x = 1To QuestionArray.ButtonsPerQuestion(Row)
        Dim llabel AsLabel
        llabel.Initialize("llabel")
        llabel.text = QuestionArray.Question(Row,x)
 
Upvote 0

DickD

Active Member
Licensed User
Where do you call LoadLayout?
You should move
Dim llabel AsLabel
inside the For / Next Loop!
B4X:
Sub LoadLayout
    Dim llabel AsLabelDim Row As Int = 1
    Dim ScrollPosition As Int = 0
    llabel.Initialize("llabel")
    qname.text = "Q1 of " &      QuestionArray.NumberOfQuestions & ": " & QuestionArray.Question(Row,0)
    For x = 1To QuestionArray.ButtonsPerQuestion(Row)
        llabel.text = QuestionArray.Question(Row,x)

should be:
B4X:
Sub LoadLayout
    Dim Row As Int = 1
    For x = 1To QuestionArray.ButtonsPerQuestion(Row)
        Dim llabel AsLabel
        llabel.Initialize("llabel")
        llabel.text = QuestionArray.Question(Row,x)
LoadLayout is called in Sub Start. I only had to move the initialization statement into the loop to make this work properly. Wasn't necessary in B4A.
 
Upvote 0
Top