Android Question Remove Duplicates From A ListView?

sule

Member
Licensed User
Longtime User
Is it possible to do a faster/better way for removing dupes from listview
B4X:
Dim i As Int,j As Int
    For i = 0 To lstFav.Size - 1
            For j = lstFav.size -1 To (i + 1) Step -1
                If lstFav.GetItem(j) = lstFav.GetItem(i) Then
                  lstFav.RemoveAt( j)
                End If
            Next
        Next
this work flawlessly but i wonder is it better way for b4a im newbie
sorry for my English
 

JTmartins

Active Member
Licensed User
Longtime User
This is me thinking very quickly...

If the itens are all of the same kind, let's say strings

Then you can do a List.Sort (one line of code)

Afterwards, it should be possible to compare an item with the one imediatly after. (only one for..next loop)

If they are equal you can eliminate the first one and move on to the next.

Opps..sorry. You mentioned LISTVIEW..I thought it was a LIST. So my post is probably useless.
 
Last edited:
Upvote 0
Top