Android Question How to Show a Spefic Number of List Items


Licensed User
Longtime User
I am using the CustomListView Object to show a clients various EMails and Phone Numbers. Since the number of Email/Phone numbers can range from 0 to 10 entries, my question is how vary the lists height so that I only show the number of list entries that each client has? If there are 5 or more entries then the list will scroll.

Thank you in advance. Jon


Licensed User
Longtime User
Thanks, I think I'll wait for the headache to subside! An example or pointing to an example would also be great! Thanks!
Upvote 0


Licensed User
Longtime User
Finally I'm fine :)

So, since you are using the CustomListView, you should simply write a routine to create an Item (as in the tutorial).

I did a quick test (it is not nice, email and numbers in one column, without labels for the headers).

It uses ContactsUtils.

clvRubrica is a CustomListView.

If FirstTime Then
    End If

    mContacts = mContactsUtils.FindAllContacts(True)
    For Each Contact As cuContact In mContacts
        Dim EmailsCount As Int = mContactsUtils.GetEmails(Contact.Id).Size
        Dim PhonesCount As Int = mContactsUtils.GetPhones(Contact.Id).Size
        Dim pnlHeight As Int
' This is "wrong": I was thinking of putting email and phone in two columns side by side.
        pnlHeight = mPhotoSide + (Max(EmailsCount, PhonesCount)) * mEmailLabelHeight
        clvRubrica.Add(CreateListItem(Contact), pnlHeight, Contact)

Sub CreateListItem(Contact As cuContact) As Panel
    Dim EventName As String = "Contact"

    Dim p As Panel
    p.Color = Colors.Black

    ' Display name
    Dim lblName As Label : lblName.Initialize(EventName)
    p.AddView(lblName, 0, 0, clvRubrica.Width - mPhotoSide , mEmailLabelHeight)
    lblName.Text = Contact.DisplayName

    ' Photo
    Dim imvPhoto As ImageView : imvPhoto.Initialize(EventName)
    p.AddView(imvPhoto, clvRubrica.Width - mPhotoSide, 0, mPhotoSide, mPhotoSide)
    Dim bmp As Bitmap = mContactsUtils.GetPhoto(Contact.Id)
    If bmp.IsInitialized Then
    End If

    Dim lstEmails As List = mContactsUtils.GetEmails(Contact.Id)
    Dim lstPhones As List = mContactsUtils.GetPhones(Contact.Id)
    Dim EmailsCount As Int = lstEmails.Size
    Dim PhonesCount As Int = lstPhones.Size

    Dim LastPhoneBottom As Int
    For i = 0 To PhonesCount -1
        Dim lblPhone As Label : lblPhone.Initialize(EventName)
        p.AddView(lblPhone, 0, lblName.Height + i * mEmailLabelHeight, (clvRubrica.Width - mPhotoSide) / 2, mEmailLabelHeight)
        Dim PhoneNum As cuPhone = lstPhones.Get(i)
        lblPhone.Text = PhoneNum.Number
        LastPhoneBottom = lblPhone.Top + lblPhone.Height

    For i = 0 To EmailsCount -1
        Dim lblEmail As Label : lblEmail.Initialize("Contact")
        p.AddView(lblEmail, 0, LastPhoneBottom + i * mEmailLabelHeight, (clvRubrica.Width - mPhotoSide) / 2, mEmailLabelHeight)
        Dim Email As cuEmail = lstEmails.Get(i)
        lblEmail.Text = Email.Email

    Return p

End Sub

mPhotoSide and mEmailLabelHeight are declared at module level (globals)

Bleah, I would have to complete the example in a decent way and publish the project. I'm sorry. :)
Last edited:
Upvote 0