Create a CLV from a List of Type

pliroforikos

Active Member
Licensed User
Hello,
In an example of clv I'm trying to create a Custom List View from a List of Type

B4X:
Type Customer(ID As String, FirstName As String, LastName As String, Phone As String)
Private Customers As List
Private CustomListView1 As CustomListView

I'm thinking to loop the values of list and create a string from all values and add them to the
clv with .AddTextItem but it will not be arranged in columns.

Any other ideas?
 

LucaMs

Expert
Licensed User
Longtime User
You are trying to fill a CustomListView.
AddTextItem allows you to add just a String, then only the FirstName, for example, or concatenating the values into a single string (using StringBuilder).
This is not the best way, anyway.

Post the code you are using to fill the CV.

Note that you posted your question in a wrong forum; next time, do it in the "Android Questions" forum.
 

pliroforikos

Active Member
Licensed User
Thank you.
Its not android question its an exercise for teaching material i'm making in b4j. I'm trying to keep it as simple as possible and yes we can create a string concatenating variables.
 

udg

Expert
Licensed User
Longtime User
Keeping your project as is, you need to add spaces or any other separation char to each type-item in order to make it as large as its column width.
Instead of concatenation you may want to use smart string letterals.
There was a similar request recently.

Sorry to be of a limited help now, but I am on my mobile phone and on a walk..
 

pliroforikos

Active Member
Licensed User
Keeping your project as is, you need to add spaces or any other separation char to each type-item in order to make it as large as its column width.
Instead of concatenation you may want to use smart string letterals.
There was a similar request recently.

Sorry to be of a limited help now, but I am on my mobile phone and on a walk..

Thank you very much here a solution adding spaces. I think it works only with monospaced fonts

B4X:
Private Sub Button1_Click
    For i = 0 To Customers.Size-1
        Private c As Customer
        Private str As String
        c = Customers.Get(i)
        Private s1, s2, s3, s4 As String
        s1 = addSpaces(c.ID, 1)
        s2 = addSpaces(c.FirstName, 2)
        s3 = addSpaces(c.LastName, 3)
        s4 = c.Phone
     
        str = $"${s1}${s2}${s3}${s4}"$
        CustomListView1.AddTextItem(str, c.ID)
    Next
End Sub

Private Sub addSpaces(s1 As String, pos As Int) As String
    If pos = 1 Then
        Do While s1.Length <= 8 Then
            s1 = s1 & " "
        Loop
    else if pos = 2 Or pos = 3 Then
        Do While s1.Length <= 20 Then
            s1 = s1 & " "
        Loop
    End If
    Return s1
End Sub

list.png

I believe my students (with a little help) will find this solution.
 
Last edited:
Top