I'm trying to use AutoCompleteEditText to search/filter contacts. My code as below:
1. It worked ok on emulator with 4-5 example contacts but I got error when click on the drop down menu. I don't know why?
2. When test on my real device with more than 200 contacts, it's very slow to type characters and it even doesn't show drop down menu. Could you please make some suggestions to improve it?
Thank you so much
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
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 ContactList As List
Dim NameSearch As AutoCompleteEditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
ContactList.Initialize
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub SearchContact(s As String)
Dim Contacts2 As Contacts2
Dim listOfContacts As List
listOfContacts = Contacts2.FindByName(s, False, True, False) 'No need Note
For i = 0 To listOfContacts.Size - 1
Dim Contact As Contact
Contact = listOfContacts.Get(i)
Dim phones As Map
phones = Contact.GetPhones ' Get all the phone numbers
If phones.Size > 0 Then
For j = 0 To phones.Size - 1
ContactList.Add(Contact.DisplayName & " (" & phones.GetKeyAt(j) & ")") ' To display like: Santa Clause (0011223344)
Next
End If
Next
NameSearch.SetItems(ContactList)
End Sub
Sub Name_ItemClick (Value As String)
ToastMessageShow(Value, False) ' Error?
End Sub
Sub Name_TextChanged (Old As String, New As String)
ContactList.Clear 'Clear list before search
SearchContact(New)
End Sub
1. It worked ok on emulator with 4-5 example contacts but I got error when click on the drop down menu. I don't know why?
2. When test on my real device with more than 200 contacts, it's very slow to type characters and it even doesn't show drop down menu. Could you please make some suggestions to improve it?
Thank you so much