Android Question sort list of CSBuilder objects

leitor79

Active Member
Licensed User
Hi,

I have a list of CSBuilder objects, and I need to sort the items.
CSBuilder objects starts with some format like "x, y" and followed by some fontawesome icons I load into a customlistiview (b4xlisttemplate).

List.Sort throws an error (csbuilder cannot be cast to java comparable)
List.SortType("ToString", Asc) also throws an error.
I've tried converting the csbuilder objects to strings and the sorting works, but I lost the fontawesome icons.

Any ideas?

Thank you,
 

emexes

Well-Known Member
Licensed User
Assuming there are not too many items in your list, just sort them in-List with a bubble sort or similar.
 

emexes

Well-Known Member
Licensed User
Like:
B4X:
Dim CS1 As CSBuilder    'need temporary variables for casting from List.Get generic object
Dim CS2 As CSBuilder
Dim DoneFlag As Boolean

Do
    DoneFlag = True

    For I = 0 to L.Size - 2    'one back from last item because dealing in pairs of elements
        CS1 = L.Get(I)
        CS2 = L.Get(I+1)

        If CS1.ToString > CS2.ToString Then
            L.RemoveAt(I)
            L.InsertAt(I + 1, CS1)
            DoneFlag = False
        End If
    Next I
Loop Until DoneFlag
should do it, but El Slacko here doesn't seem to have updated his B4J to a CSBuilder version yet, so... not tested.
 
Last edited:
Top