Android Question Sort contacts on TimesContacted

RAJAN MBA

Member
Licensed User
Longtime User
How to sort contacts based on the number of times contacted? I Know both codes tried are wrong:
B4X:
'listofContacts is a list
listofContacts = Contacts2.GetAll(True,False)
listofContacts.Sort(Contact.TimesContacted)
and
B4X:
'listofContacts is a list
listofContacts = Contacts2.GetAll(True,False)
listofContacts.SortType("TimesContacted",True)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You will need to create a type that holds the contact object and the count:
B4X:
Type ContactAndTimes (Cont As Contact, Times As Int)

B4X:
Dim list1 As List
list1.Initialize
For Each c As Contact In listOfContacts
 Dim t As ContactAndTimes
 t.Initialize
 t.Cont = c
 t.Times = c.TimesContacted
 list1.Add(t)
Next

'now you can sort the new list
list1.SortType("Times", True)
 
Upvote 0
Top