I have the following problem:
With ContactUtils I receive several contacts phone numbers.
Sometimes it's just 1 phone number, sometimes there are 5 phone numbers and sometimes I there is no phone number.
Now I want to write this phone numbers in up to 4 fields (e.g .: EditText or in a table).
The first difficulty is already now, I get the phone number as ArrayList in this format [Phone Type = Business, Number = + 49-7171-XXXXXX, IsInitialized = true] and in the log file all 4 telephone numbers are shown, but how can I now write them into 4 separate EditText fields (see example)?
B4X:
For Each phone As cuPhone In ContactsUtils1.GetPhones(Kontakt.Id)
Dim Kontakte_Telefon_1, Kontakte_Telefon_2, Kontakte_Telefon_3, Kontakte_Telefon_4 As String
Kontakte_Telefon_1 = ContactsUtils1.GetPhones(Kontakt.Id).Get(0)
Kontakte_Telefon_2 = ContactsUtils1.GetPhones(Kontakt.Id).Get(1)
Kontakte_Telefon_3 = ContactsUtils1.GetPhones(Kontakt.Id).Get(2)
Kontakte_Telefon_4 = ContactsUtils1.GetPhones(Kontakt.Id).Get(3)
Log(""&phone.Number&"")
Next
dim l as list = ContactsUtils1.GetPhones(Kontakt.Id)
' now iterate through the list to get a phone object...
' add the first phone.Number to textfield1, the second to Tectfield2 and so on
dim l as list = ContactsUtils1.GetPhones(Kontakt.Id)
' now iterate through the list to get a phone object...
' add the first phone.Number to textfield1, the second to Tectfield2 and so on
Yes I tried to get the phone numbers directly from the list with this code:
B4X:
Dim allNumbers As List = ContactsUtils1.GetPhones(Kontakt.Id)
For Each phoneNumber As cuPhone In allNumbers
Kontakte_Telefon_1 = phoneNumber.Number
Log(Kontakte_Telefon_1)
Next
The result is, that I get the first phone number correctly, but not more than one phone number.
In the log file I get all 4 numbers.
My problem is ... how to iterate through the list, to get all 4 numbers, because in this code there is no Getter.
Dim allNumbers As List = ContactsUtils1.GetPhones(Kontakt.Id)
for i = 0 to allNumbers.size-1
dim ph as Phone = allNumbers.get(i)
log($"${i}: ${ph.number}"$)
next
Dim allNumbers As List = ContactsUtils1.GetPhones(Kontakt.Id)
For i = 0 To allNumbers.size-1
Dim ph As cuPhone = allNumbers.get(i)
Log($"${i}: ${ph.number}"$)
Next
Instead od using Kontakte_Telefon_1, Kontakte_Telefon_2, Kontakte_Telefon_3 and Kontakte_Telefon_4
Use
Private Kontakte_Telefon(3) As String
And Kontakte_Telefon(0), Kontakte_Telefon(1), Kontakte_Telefon(2) and Kontakte_Telefon(3)
Hello Klaus,
you pointed me to the right direction! Thank you very much! The solution is ...
B4X:
Dim allNumbers As List = ContactsUtils1.GetPhones(Kontakt.Id)
Private Kontakte_Telefon(allNumbers.size) As String
For i = 0 To allNumbers.size -1
Dim ph As cuPhone = allNumbers.get(i)
Kontakte_Telefon(i) = ph.Number
Next
The next problem is, that it works only with contacts, which have exactly 4 phone numbers ... because the Database wants to receive 4 fields ... but I'm sure I will find a solution like "If Kontakte_Telefon(1) = "" Then ...