Android Question Example for LazyLoading from jRDC2

AymanA

Active Member
Licensed User
Hi All,

I can load/SELECT ALL data in a table from jRDC2 (mysql DB) with no problem, but I think this is not perfect in case of thousands of rows to return/SELECT from App performance standpoint, also I am aware that I can use LIMIT to limit the number of rows; however I am not sure how to return/Load the next number of rows when the user scroll to the next view/number of rows, I understand the concept by following:

But do we have a full example from App side how to implement this, or get the next number of visible rows from jRDC2?

Note: I have searched the forum but can not find a clear way to do this.

Thanks for your help with this!

Kind regards,
Ayman
 

Alexander Stolte

Expert
Licensed User
Longtime User
Download 100 items.
But it depends on how the content is displayed, if only 5 rows fit on the screen, then to preload 100 items from the DB is quite a lot. The loading time is also longer with 100 records than with 30.

Here is an example:
SQL:
SELECT * FROM mytable LIMIT ?,30;
This returns 30 rows at the given offset.
if you load the page for the first time, then the questionmark value is a 0, but if you have already items in the list then put this to the questionmark:
B4X:
xclv.size -1
Or from your local SQLite-DB count all your rows and put this as parameter.

B4X:
Sub xclv_page2_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)

If LastIndex > = xclv_page2.Size -1 Then 'if lazy loading reach the end of the list, then load more from the DB
      
        Dim DR As ResultSet = Main.content_sql.ExecQuery("SELECT MAX(rowid) AS rowid FROM mytable")
        Do While DR.NextRow
            GetContent(DR.GetInt("rowid"))'rowid is the offset for your LIMIT offset
        Loop
        DR.close

    End If

End Sub

I'm not good at explaining. ?
but I just put that in my app yesterday.
 
Upvote 0

AymanA

Active Member
Licensed User
Thank you so much Erel and Alexander, both your comments made it clear on how I will do this, CLV_ReachEnd and the offset for the limit!! This is great, thank you!

One more question if you do not mind what if i will have search, so does this mean that everytime the user will search for keyword for example: ABC, it will SELECT when the user hit A then another call/select when the user hit B, and then third when hit C?

I believe this can be achieved by clear the first visible 30/100 and use LIKE syntax in jRDC2 side , but what do you think is the best practice for search in jRDC2/CLV to show the output?
 
Upvote 0
Top