The test program below should always find an entry in the list. But it never does. It appears IndexOf doesn't work?
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type Test (Str1 As String, Str2 As String, id1 As Int, Id2 As Int)
Dim TestList As List
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim LabelTest As Label
Dim LabelList As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
LabelTest.Initialize("LabelTest")
LabelList.Initialize("LabelList")
LabelTest.Text = "Click To Find"
LabelList.Text = "Clcik To Show List"
FillTestList
Activity.AddView(LabelTest,40,10,300,65)
Activity.AddView(LabelList,40,140,300,65)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub FillTestList
TestList.Initialize
For i = 0 To 10
Dim AddTest As Test
AddTest.Initialize
AddTest.id1 = i
AddTest.id2 = i + 1
AddTest.Str1 = "Test" & i
AddTest.Str2 = "Test" & (i + 1)
TestList.Add(AddTest)
Next
End Sub
Sub LabelTest_Click
Dim i As Int
Dim SearchTest As Test
Dim lbl As Label
lbl.Initialize("")
lbl = Sender
SearchTest.Initialize
i = Rnd(0,10)
SearchTest.id1 = i
SearchTest.id2 = i + 1
SearchTest.Str1 = "Test" & i
SearchTest.Str2 = "Test" & (i + 1)
If TestList.IndexOf(SearchTest) > -1 Then
lbl.Text = "Found: " & SearchTest.id1 & " " & SearchTest.Str1
Else
lbl.Text = "Not Found: " & SearchTest.id1 & ", " & SearchTest.Id2 & ", " & SearchTest.Str1 & ", " & SearchTest.Str2
End If
End Sub
Sub LabelList_Click
InputList(TestList,"Test IndexOf Search",-1)
End Sub