I made a class, I instantiated objects of this class and add them to a list.
The problem is that when I want to do a search for a particular object in the list, the indexOf function not seem to find anything.
What am I doing wrong? Do I have to create my own search method?
Thanks in advance
The class 'persona':
The main code:
The problem is that when I want to do a search for a particular object in the list, the indexOf function not seem to find anything.
What am I doing wrong? Do I have to create my own search method?
Thanks in advance
The class 'persona':
B4X:
'Class module
Sub Class_Globals
Private fx As JFX
Private nombre As String
Private apellido As String
Private fechaNacimiento As Long
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(aNombre As String, aApellido As String, aFechaNacimiento As Long)
nombre=aNombre
apellido=aApellido
fechaNacimiento=aFechaNacimiento
End Sub
Public Sub obtenerNombre As String
Return nombre & " " & apellido
End Sub
Public Sub getEdadActual As Int
Return getEdadHasta(DateTime.Now)
End Sub
Public Sub getEdadHasta(fecha As Long) As Int
Dim diferencia As Long
diferencia= fecha - fechaNacimiento
Return Floor(diferencia/DateTime.TicksPerDay/365)
End Sub
The main code:
B4X:
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim personList As List
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Principal") 'Load the layout file.
MainForm.Show
personList.Initialize
For i=0 To 10
Dim p As persona
p.Initialize("NamePerson"&i, "LastName", DateTime.DateParse ("01/28/1960"))
personList.Add(p)
Next
For i=0 To personList.Size-1
Dim temporal As persona
temporal= personList.Get(i)
Log(temporal.obtenerNombre)
Next
Dim p As persona
p.Initialize("NamePerson1", "LastName", DateTime.DateParse ("01/28/1960"))
Log( personList.IndexOf(p))
End Sub