Hi everyone! I need to sort the following items
from:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
to
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
FIrst is must look for "sn" (priority) and sort the number of part in ascending. (The same with "ns").
The code below is what I am trying to work on.
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
To be honest I don't understand this code
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
I appreciate any help and the time.
			
			from:
			
				B4X:
			
		
		
		sn, 1004
sn, 1003
sn, 1002
sn, 1001
sn, 1000
ns, 1014
ns, 1012
ns, 1011
ns, 1010
			
				B4X:
			
		
		
		sn, 1000
sn, 1001
sn, 1002
sn, 1003
sn, 1004
ns, 1010
ns, 1011
ns, 1012
ns, 1014The code below is what I am trying to work on.
			
				B4X:
			
		
		
		Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Type Person (sn As String, number As Int)
    Private ComparatorSort As B4XComparatorSort
    Private PersonComparator1 As PersonComparator
    Private Persons As List
    Private CustomListView1 As CustomListView
End Sub
Public Sub Initialize
    ComparatorSort.Initialize
    PersonComparator1.Initialize
    Persons.Initialize
    Persons.Add(CreatePerson("sn", "1001"))
    Persons.Add(CreatePerson("sn", "1002"))
    Persons.Add(CreatePerson("sn", "1004"))
    Persons.Add(CreatePerson("sn", "1003"))
    Persons.Add(CreatePerson("sn", "1000"))
    Persons.Add(CreatePerson("ns", "1014"))
    Persons.Add(CreatePerson("ns", "1010"))
    Persons.Add(CreatePerson("ns", "1011"))
    Persons.Add(CreatePerson("ns", "1012"))
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    ComparatorSort.Sort(Persons, PersonComparator1)
    For Each p As Person In Persons
        'CustomListView1.AddTextItem($"${p.sn}, ${p.Status}"$, p)
        Log($"${p.sn}, ${p.number}"$)
    Next
End Sub
Public Sub CreatePerson (sn As String, number As Int) As Person
    Dim t1 As Person
    t1.Initialize
    t1.sn = sn
    t1.number = number
    Return t1
End Sub
			
				B4X:
			
		
		
		Public Sub Compare (o1 As Object, o2 As Object) As Int
    Dim p1 As Person = o1
    Dim p2 As Person = o2
    If p1.sn = "sn" And p2.sn <> "sn" Then Return -1
    If p2.sn = "sn" And p1.sn <> "sn" Then Return 1
    If p1.number > p2.number Then
        If p1.number > p2.number Then Return -1
        If p1.number < p2.number Then Return 1
    End If
    Return p1.sn.CompareTo(p2.sn)
End Sub 
				 
 
		 
 
		 
 
		