I need help.
I have a list whose contents must never change. So I create a new list and copy the contents of the original list using AddAll.
The problem is when I change the contents of the new list the original gets changed too.
What am I doing wrong? Code seems to work fine on a list of integers but not on a list of custom type.
I have a list whose contents must never change. So I create a new list and copy the contents of the original list using AddAll.
The problem is when I change the contents of the new list the original gets changed too.
What am I doing wrong? Code seems to work fine on a list of integers but not on a list of custom type.
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
Dim OriginalList, PreviewList As List
Dim AdjustedOffset As Int
Type cType(name As String, time As Int)
End Sub
Sub Activity_Create(FirstTime As Boolean)
OriginalList.Initialize
For i = 100 To 1000 Step 100
Dim x As cType
x.Initialize
x.time = i
OriginalList.Add(x)
Next
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub activity_Click
AdjustedOffset = AdjustedOffset + 100
AdjustOffset(AdjustedOffset)
End Sub
Sub AdjustOffset(ms As Int)
PreviewList.Initialize
PreviewList.AddAll(OriginalList)
For Each lkiiwe As cType In PreviewList
lkiiwe.time = lkiiwe.time + ms
Log(lkiiwe.time)
Next
Dim Orig1 As cType = OriginalList.Get(0)
Log("adjusted offset: "& ms)
Log("Orig1: "& Orig1.time) ' THIS SHOULD NOT BE CHANGING!!!!
End Sub