Android Question Auto scroll to item on list? [SOLVED][IMPROVED]

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

I have a long list of name > 1000 , rather than manually scroll through to find Larry I would like to start typing Larry and have the pointer move to the "L'S" when L is typed and then to La etc.

I have tried searching but probably couldn't phrase to question suitably.

Thanks in advance.
Roger
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
rraswisak,

You are a bloody genius. This works perfectly, at least on my V20, I still need to check on older and later versions of Android. As it stands it does exactly what I was trying to do and I don't see any problems.


Regards Roger



B4X:
Sub Process Global
   Private KBentry As Boolean = True
End Sub

Sub Globals
   Private wbvTable As WebView        'Added in Designer
End Sub

Sub DispSelectedItem_textchanged(Old As String, New As String)
    If KBentry Then                                        'If DispSelectedItem.text is changed programmatically KBEntry is set to False.
        If RowIDList.Size = 0 Then
            KBentry = False
            DispSelectedItem.Text = "NO SITES IN LIST"
            Return
        End If

        Private SearchFor As String
        SearchFor = DispSelectedItem.Text
        FindString(SearchFor) 
    Else  
        KBentry = True
    End If      
End Sub

Sub FindString(s As String)
    Dim jo As JavaObject = wbvTable
    jo.RunMethod("findAllAsync", Array(s))
End Sub
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
This is wrong... jenius is belong to @Erel, my resolution came from his resolution too... :)

I just read your two question thread and has conclusion that all you need is to find a string in webview.


Thanks Erel.

rasswisak your genius was figuring out what I really needed when I couldn't.

Roger
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All

An improved solution.
The "FindString" Sub has one small weakness it searches for a match anywhere in the string.
EG: If you were to search for "South Town" and typed SOUTH it may scroll to "City South", a long way from the records starting with South.

I have added a search for Records that start with the typed string but does not scroll. The complete location name is passed to "FindString" and the display scrolls to the first record starting with South. The search is not case sensitive.

Regards Roger

B4X:
Sub DispSelectedItem_textchanged(Old As String, New As String)
    Private SearchFor, SiteName, SiteNameUP, SearchForUP As String
    If RowIDList.Size < 1 Then
        KBentry = False
        DispSelectedItem.Text = "NO SITES IN LIST"   
        Sleep(500)
    Else
        If KBentry Then             
'Search for first Entry starting with text entered by keyboard.
            SearchFor= DispSelectedItem.Text
            For CurrentIndex = 0 To RowIDList.Size - 1
                SiteName = SQL1.ExecQuerySingleResult("SELECT SiteName FROM sites WHERE rowid = " & RowIDList.Get(CurrentIndex))
                SiteNameUP = SiteName.ToUpperCase                'SiteName and SearchFor converted to UpperCase to make search case insensitive.
                SearchForUP = SearchFor.ToUpperCase
                
                If SiteNameUP.StartsWith(SearchForUP) Then        'Finds first Entry starting with entered text but does not scroll to it.                   
                    FindString(SiteName)                        'FindString finds the full site name and scrolls the lis to display it.
                    Exit
                End If
                
            Next       
        End If
    End If
    KBentry = True           
End Sub

Sub FindString(s As String)
    Dim jo As JavaObject = wbvTable
    jo.RunMethod("findAllAsync", Array(s))
End Sub
 
Upvote 0

rraswisak

Active Member
Licensed User
Longtime User
after first match found, you can also scroll to next match string with:

B4X:
Sub FindNextString()
    Dim jo As JavaObject = wbvTable
    jo.RunMethod("findNext", Array(True))
End Sub

by the way, if you want to find more than one word, then the string key should be full word for better result
 
Upvote 0
Top