Android Question List of custom Type

bhangorix

Member
Hi,
I'm trying to load data into list with custom type. But the list value always show only the last list.
I'm trying to load it to KeyValueStore after that

Can anybody tell me what i missed here

here's my sample code
B4X:
Sub Process_Globals
    Type tPar (pgroup As String, pcode As String, attr1 As String)
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim listPar As List
    Dim dtPar As tPar
    
    For i = 1 To 5
        listPar.Initialize
        For j = 1 To i
            dtPar.Initialize
            dtPar.pgroup = "group" & i
            dtPar.pcode = "pcode" & j
            dtPar.attr1 = "attr1-" & j
            listPar.Add(dtPar)
        Next
        Log("------------------")
        For h = 0 To listPar.Size-1
            Log(listPar.Get(h))
        Next
        'If Starter.kvs.put(pgroup, listPar) = False Then ToastMessageShow("Error put keystore", True)
    Next
End Sub

Result
B4X:
------------------
[IsInitialized=true, attr1=attr1-1, pcode=pcode1
, pgroup=group1]
------------------
[IsInitialized=true, attr1=attr1-2, pcode=pcode2
, pgroup=group2]
[IsInitialized=true, attr1=attr1-2, pcode=pcode2
, pgroup=group2]
------------------
[IsInitialized=true, attr1=attr1-3, pcode=pcode3
, pgroup=group3]
[IsInitialized=true, attr1=attr1-3, pcode=pcode3
, pgroup=group3]
[IsInitialized=true, attr1=attr1-3, pcode=pcode3
, pgroup=group3]
 

bhangorix

Member
You need to put Dim dtPar as tPar inside the loop. Otherwise you are not creating a new object each iteration.

Better option is to hover over tPar type - select - Generate Create Type sub and use it inside the loop.

Alright.... Work like a charm

Thanks Erel
 
Upvote 0
Top