Android Question Webview Extras .pagedown [Solved]

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

I have been trying out ideas in Klauses SQLlight2 example.
SQLlight2 example is a Webview with a table of names of people and associated citys.

When a new record is entered it is in the Activity "Edit", if the the user returns to the "Main" activity immediately I want the new record displayed. Depending on the number of records this may require the page to be scrolled X times.

Below is the Activity_Resume in the Main activity, in this I find the "CuurentIndex" of the new record and attempt to Scroll X times to bring that record to the Webview.

Webviewextras.pagedown scrolls the page so that record just out of view at the bottom is displayed near the top of the Webview. I thought putting this in a loop to Scroll X times would bring a record further down the list into view. It doesn't, it appears to scroll down from the top each time.

Zip Attached

Any clues greatly appreciated.

Regards Roger

Sub Activity_Resume
    Private RowID As Int                                'New for SQLiteLight2MOD..
    'Private TempID As Int                                'New for SQLiteLight2MOD..
    Private Scroll As Int
    If SQL1.IsInitialized = False Then
        SQL1.Initialize(File.DirInternal, "persons.db", True)
    End If

    '***** 'New for SQLiteLight2MOD.    Sets CurrentIndex to correct value after Webview is sorted by SiteName in ShowTable Sub.
    If NewRecord = True Then                          'NewRecord set in AcitivityEdit
        Private TempID As Int
        RowID  = SQL1.ExecQuerySingleResult("SELECT max(rowid) FROM persons")            ' Find RowID of added Site    which is the largest number
        For CurrentIndex  = 0 To RowIDList.Size - 1                                                        'Loop through all possible values of "CurrentIndex" to find RowID
            'If RowID = SQL1.ExecQuerySingleResult("SELECT rowid FROM persons WHERE rowid = " & RowIDList.Get(CurrentIndex)) Then Exit

            TempID  = SQL1.ExecQuerySingleResult("SELECT rowid FROM persons WHERE rowid = " & RowIDList.Get(CurrentIndex))
            If TempID = RowID Then            Exit                                                                'Exit loop when "CurrentIndex" holds the RowID of the newest entry
'************************Scroll page to display new entry on screen*****************************
        wbvExtra1.pageUp(wbvTable, True)                    'Sets Webview displaying top entry
Log("CurrentIndex   "&CurrentIndex)                            'Currentindex is the position on the table of the new entry
        If CurrentIndex > 13 Then                                    'If new entry is off screen scroll X times to show on screen
            Scroll = CurrentIndex / 13                                '"Scroll" is the number of times the page has to scroll to display new entry
Log("Scroll    "&Scroll)
            For i = 1 To Scroll
                wbvExtra1.pageDown(wbvTable, False)
        End If
        NewRecord = False
    End If
    If CurrentIndex >= 0 Then
    End If
End Sub


    20.3 KB · Views: 208


Licensed User
Longtime User
The PageDown method returns a Boolean to indicate whether the page was successfully scrolled.

Is the PageDown method asynchronous?
Presumably you thought about this and added the Sleep(100) to your code to allow time for the webview to be scrolled?
100ms might not be enough time for a large webpage to be scrolled - different devices with different CPUs will probably take different amounts of time to scroll.
Can you change 100ms to 1000ms?

Report back whether the PageDown method returns True or False each time it's called and whether a longer Sleep gives the PageDown method time to complete before it is called again.
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Thanks Warwound,

I changed the Sleep to 1000ms as you suggested and yes it worked, far greater delay than I thought.
I've wound back to 500ms [300ms, no go], it works but hard on the eyes for a long list. To cover all the varieties of Android and processors the delay would have to be closer to 1000.

wbvExtra1.pageDown(wbvTable, False) returns "True" with or without the sleep delay. It thinks it has been successful when it really hasn't.

Thanks for the help, I should have gone for the extreme delay myself but thought 100ms was extreme.

Perhaps what is needed is a WebView.scrollto(x,y) [Says he who has no idea how to do this]

Last edited:
Upvote 0