B4J Question Ways to seach a listview

ThRuST

Well-Known Member
Licensed User
Longtime User
I would like to know various ways how to search a listview. Since everyone uses their own ways it would be great to know various ways. Short and effective methods would be the best.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
I came up with this solution myself. But I'd like to know various way as well.
B4X:
Dim findstr = "string to find"
Dim itemstr As String

For Each n As String In Listview.Items
    itemstr = n
    If (itemstr.Contains(findstr)) Then
        MainForm.Title = "Item " & itemstr & " was found"
        Exit
    Else
        MainForm.Title = "No match"
    End If
Next
 
Last edited:
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
In this second version I added an int called val. This makes it possible to use a For Each loop with both names and in this case, a virtual index.
You have to add a bunch of items to the listview yourself, by code or manually. It is up to you
B4X:
Dim findstr = Textfield.Text
Dim itemstr As String
Dim val As Int = 0

For Each n As String In Listview.Items
    itemstr = n
    If (itemstr.Contains(findstr)) Then
        MainForm.Title = "Item " & val & " was found"
        Exit
    Else
        MainForm.Title = "No match"
    End If
    val = val + 1
Next
 
Last edited:
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Good idea, I changed them with code tags Do you mind to give away your clever way to search a listview? I assume the For/Next way is better so that the index can be tracked properly.
Do you recommend to search by Contains or is there a prefferable way?
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…