Adding at listview to a panel

eatyourpeas

Member
Licensed User
Longtime User
SO. I am trying to scroll through a list in a panel using listview. When I assign the listview (listview1) to the panel (testpanel), nothing happens. when I assign listview1 to activity then it works.

I'd be grateful if someone could explain why when the listview is visible when part of activity, but not when part of the panel.

this is the code:

I think I must have completely missed the point of panels. Any advice very gratefully received....

'These variables can only be accessed from this module.
Dim BoneScoreAIList As List
Dim TestPanel As Panel
Dim ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("BoneAgesLayout")
TestPanel.initialize("TestPanel")
ListView1.Initialize("ListView1")
BoneScoreAIList.Initialize
BoneScoreAIList.AddAll(Array As String("A","B","C","D","E","F","G","H","I"))

For i = 0 To BoneScoreAIList.Size - 1
ListView1.AddSingleLine(BoneScoreAIList.Get(i))
Next
Testpanel.AddView(ListView1,0,0,100%x,100%y)
End Sub
 

Cableguy

Expert
Licensed User
Longtime User
Try removing the listview from the activity using ListView.RemoveView and then change its parent to the panel using Panel1.AddView(ListView1,....)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
What do you have in the BoneAgesLayout layout file ?
If TestPanel and ListView1 are already in there you must not initialize them.
Could you post your project as a zip file, so we could look at it to find out what happens.

Best regards.
 
Upvote 0

eatyourpeas

Member
Licensed User
Longtime User
Very many thanks
Here it is - really an experimental thing to start with
If you change the line:
Testpanel.AddView(ListView1,0,0,100%x,100%y)
to
Activity.AddView(ListView1,0,0,100%x,100%y)

then it works, except the listview is not a child of Testpanel
 

Attachments

  • BoneAges.zip
    6.2 KB · Views: 263
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Just remove the commented lines and it works...
As Klaus said, you should not initialize views adde in the designer...

B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("BoneAgesLayout")
'TestPanel.initialize("TestPanel") is not needed
'ListView1.Initialize("ListView1") is not needed
'ListView1.RemoveView is not needed
BoneScoreAIList.Initialize
BoneScoreAIList.AddAll(Array As String("A","B","C","D","E","F","G","H","I"))

For i = 0 To BoneScoreAIList.Size - 1
ListView1.AddSingleLine(BoneScoreAIList.Get(i))
Next
'Testpanel.AddView(ListView1,0,0,100%x,100%y) is not needed
End Sub
 
Upvote 0

eatyourpeas

Member
Licensed User
Longtime User
Many thanks

tho I still find that it does need the line - can't see anything without it:


TestPanel.AddView(ListView1, 0, 0, 100%x, 100%y)

Please set me straight if I have misunderstood this
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
That's the code, it works, I tested it:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("BoneAgesLayout")
    BoneScoreAIList.Initialize
    BoneScoreAIList.AddAll(Array As String("A","B","C","D","E","F","G","H","I"))

    For i = 0 To BoneScoreAIList.Size - 1
        ListView1.AddSingleLine(BoneScoreAIList.Get(i))
    Next
End Sub
That's exactly the code cableguy showed you !

Best regards.
 

Attachments

  • BoneAges1.zip
    6.2 KB · Views: 259
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…