Hi
I am trying to implement a list of user defined types. The documentation for the 'list' says it can hold any object, but I am finding that with a user defined type this is not working as I expected.
Basically I am trying to use a list object to hold named/pairs, I have defined a 'type' with a string and an int, I can then create these and access the properties/values via the . notation (and intellitype shows them).
I can add them to a list object with no errors, but when I try to retrieve then I only seem to get the last one no matter what position in the list I 'Get'.
Example is below, the first 3 rows of the list view get updated as expected, showing to me that the user defined type 'b' is working.
I would expect the last 3 rows to be repeats as I am getting from each position in the list, but I get the last item added from each position? I am getting an object of the correct type back into 'c' but it is always the same one?
Thoughts, or point out the obvious (but not to me:-() mistake
Graham
I am trying to implement a list of user defined types. The documentation for the 'list' says it can hold any object, but I am finding that with a user defined type this is not working as I expected.
Basically I am trying to use a list object to hold named/pairs, I have defined a 'type' with a string and an int, I can then create these and access the properties/values via the . notation (and intellitype shows them).
I can add them to a list object with no errors, but when I try to retrieve then I only seem to get the last one no matter what position in the list I 'Get'.
Example is below, the first 3 rows of the list view get updated as expected, showing to me that the user defined type 'b' is working.
I would expect the last 3 rows to be repeats as I am getting from each position in the list, but I get the last item added from each position? I am getting an object of the correct type back into 'c' but it is always the same one?
Thoughts, or point out the obvious (but not to me:-() mistake
Graham
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ListView1 As ListView
Type namedpair (name As String, val As Int)
End Sub
Sub Activity_Create(FirstTime As Boolean)
activity.LoadLayout("tab1layout")
Dim b As namedpair
Dim c As namedpair
Dim List1 As List
list1.Initialize
'action 1
b.name="Fred"
b.val=20
list1.Add(b)
listview1.AddSingleLine(b.name & "="& b.val)
'action 2
b.name="Bob"
b.val=30
list1.Add(b)
listview1.AddSingleLine(b.name & "="& b.val)
'action 3
b.name="Mary"
b.val=40
list1.Add(b)
listview1.AddSingleLine(b.name & "="& b.val)
'action 4
c=list1.Get(0)
listview1.AddSingleLine(c.name & "="& c.val)
'action 5
c=list1.Get(1)
listview1.AddSingleLine(c.name & "="& c.val)
'action 6
c=list1.Get(2)
listview1.AddSingleLine(c.name & "="& c.val)
End Sub