Android Question Test if contact has phone number(s)

Startup

Active Member
Licensed User
Longtime User
Using ContactUtils I list the contacts and the user selects a contact which gives him a list of phone numbers for that contact. Here's the relevant code. In the first sub I list the contacts. In the second sub I list the phone numbers for the selected contact (from the first sub) if there are any. If there aren't any phone numbers the second sub displays a blank in the "listPhonenums" display view. Instead of a blank I would like to display a message "No phone number(s) for this contact. How can I code to test if a contact has any phone numbers?

B4X:
Sub GetContacts
    Dim allContacts As List = cu.FindAllContacts(True)
   allContacts.SortTypeCaseInsensitive("DisplayName", True)
   For Each c As cuContact In allContacts
      listContactsview.AddSingleLine2(c.DisplayName, c)
   Next
End Sub

Sub listContactsview_ItemClick (Position As Int, Value As Object)
    Dim c As cuContact = Value
    listPhonenums.Clear
    For Each phone As cuPhone In cu.GetPhones(c.Id)
        listPhonenums.AddSingleLine(phone.Number & " , " & phone.PhoneType)
    Next
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub listContactsview_ItemClick (Position As Int, Value As Object)
    Dim c As cuContact = Value
    listPhonenums.Clear
    If cu.GetPhones(c.Id).Size = 0 Then
      listPhonenums.AddSingleLine("No phone numbers")
    Else
       For Each phone As cuPhone In cu.GetPhones(c.Id)
          listPhonenums.AddSingleLine(phone.Number & " , " & phone.PhoneType)
       Next
  End If
End Sub
 
Upvote 0

Startup

Active Member
Licensed User
Longtime User
B4X:
Sub listContactsview_ItemClick (Position As Int, Value As Object)
    Dim c As cuContact = Value
    listPhonenums.Clear
    If cu.GetPhones(c.Id).Size = 0 Then
      listPhonenums.AddSingleLine("No phone numbers")
    Else
       For Each phone As cuPhone In cu.GetPhones(c.Id)
          listPhonenums.AddSingleLine(phone.Number & " , " & phone.PhoneType)
       Next
  End If
End Sub

Nice. Thanks Erel!
 
Upvote 0

agus mulyana

Member
Licensed User
Longtime User
Hi Erel, i have tested that code, but i can not find my phone nbumber yet,, for email list, that code is working properly, help me..
thank's
 
Upvote 0
Top