Android Question First Item in ScrollView not Displaying

Frank Cazabon

Member
Licensed User
Longtime User
Hi,

I think I must have a logic error here and hope someone else can see it as I've been looking at it too long unsuccessfully.

I am adding items to a scrollview but the first one never displays.

My code:

B4X:
    Dim scvApproval As ScrollView ' declared in the Globals sub and created in a designer panel

    Dim Approvals As List
    Approvals = DBUtils.ExecuteMemoryTable(SQLLite, "SELECT awb_number, rte_name FROM TransferAWBs ORDER BY rte_name, awb_number", Null, 0)
    lstChecks.Initialize
    scvApproval.Panel.RemoveAllViews
   
    For i = 0 To Approvals.Size - 1
        Dim Approval() As String
        Approval = Approvals.Get(i)

        Dim chk As CheckBox
        chk.Initialize("")
        chk.Text = "Transfer " & Approval(0) & " to " & Approval(1)
        lstChecks.Add(chk)
        scvApproval.Panel.AddView(chk, 0, height * (i - 1), 400dip, height)
    Next

Can anyone spot what I am doing wrong?
 

Frank Cazabon

Member
Licensed User
Longtime User
I got it!

the first time in, i = 0 so height * (i - 1) so the Top was getting set to a negative value.

Now if only I could get the scrollview to actually scroll.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
This line
scvApproval.Panel.AddView(chk, 0, height * (i - 1), 400dip, height)
must be
scvApproval.Panel.AddView(chk, 0, height * i), 400dip, height)
In your code, if i = 0 the Top propety is equal to - height !

Don't forget to set the height of the scrollviews internal panel.
scvApproval.Panel.Height = Approvals.Size * height
 
Upvote 0

Frank Cazabon

Member
Licensed User
Longtime User
This line
scvApproval.Panel.AddView(chk, 0, height * (i - 1), 400dip, height)
must be
scvApproval.Panel.AddView(chk, 0, height * i), 400dip, height)
In your code, if i = 0 the Top propety is equal to - height !

Don't forget to set the height of the scrollviews internal panel.
scvApproval.Panel.Height = Approvals.Size * height

Thanks, I had lifted the code from an example hereabouts but the loop started at 1, not 0 and I hadn't noticed that.

Thanks also for the tip on the Panel.Height as that now allows me to scroll
 
Upvote 0
Top