Android Question jRDC2, Customlistview, MySQL

kisoft

Well-Known Member
Licensed User
Longtime User
How can I adapt the code in Custmlistview to load an image and text from a remote MySQL database?
Here is an example code (b4j) where I load one image from the database.

B4X:
Sub GetRecord
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("czytaj2",Null)
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
    
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
          
        If res.Rows.Size > 0 Then
      
        Dim row() As Object = res.Rows.Get(a)
                Label1.Text = row(res.Columns.Get("col1"))
            Label2.Text = row(res.Columns.Get("col2"))
        Label3.Text = row(res.Columns.Get("col3"))
        
        Dim ima As B4XBitmap
        ima = BytesToImage(row(res.Columns.Get("image")))
        ImageView1.SetImage(ima)

        Else
        Log("ERROR: " & j.ErrorMessage)
        End If
    End If
    j.Release
End Sub

Public Sub BytesToImage(bytes() As Byte) As B4XBitmap
   Dim In As InputStream
   In.InitializeFromBytesArray(bytes, 0, bytes.Length)
   Dim bmp As Image
   bmp.Initialize2(In)
   Return bmp

End Sub

Sub Button3_Click
    a=a+1
    If a =10 Then a=0
    GetRecord
End Sub

https://www.b4x.com/android/forum/threads/b4x-xui-customlistview-lazy-loading-virtualization.87930/
 

kisoft

Well-Known Member
Licensed User
Longtime User
Hi
It's hard to say how many pictures will be, it depends on the user. I think not more than 100. I do not know how to do it so that the images scroll smoothly.
Is there an example of how to do it?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Call ima.Resize to decrease the bitmaps sizes. However lazy loading is indeed recommended when showing a list of bitmaps.

You can start with a simple and not the most efficient approach:
- Download the first 10 items and add them.
- Download all the other items.
- Store the bitmaps in a global List.
- Use lazy loading to create the items as needed.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…