B4J Question ImageDownloader use correctly

MarcoRome

Expert
Licensed User
Longtime User
Hi Erel, All.
In another thread ( https://www.b4x.com/android/forum/threads/okhttputils-2-95-and-java-11.125592/post-784428 )
I read: " Note that you are not using ImageDownloader correctly but it is not relevant for this discussion "

The code in example is:

B4X:
.....
    mappa_foto.Initialize
    Dim lista_foto As List = Array As String("1.jpg", "2.jpg","3.jpg", "4.jpg","1608043208527.jpg","1608044037413.jpg","1608042127164.jpg","1608042432794.jpg","1608044968333.jpg","1608045457077.jpg")
    Dim example_test As List = Array As String("a","b","c","d","1","2","3","4","5","6")
   
    For i = 0 To lista_foto.Size - 1
        'Prelevo immagine
        Dim immagine As String = "https://xxxx/" & lista_foto.Get(i)
        clv_ricorda_quel_giorno.Add(CreateListAndrea(example_test.Get(i), immagine, clv_ricorda_quel_giorno.AsView.Width, 60dip, 0, ""),"")
   
    Next
    'Download Picture <---------------------------------------HERE
    Dim id As ImageDownloader
    id.Initialize
    id.Download(mappa_foto)
    .....
   
   
Sub CreateListAndrea( titolo As String, foto As String, Width As Int , Height As Int, riga As Int,  parametri As String ) As Pane
    Dim p As B4XView = xui.CreatePanel("p")
    #if B4A
        p.SetLayout(0, 0, Width, Height)
    #else if B4i
        p.SetLayoutAnimated(0, 1, 0, 0, Width, Height) 'set the size before the layout is loaded
    #else if B4j
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    #End If
   
    p.LoadLayout("lay_clv_ricordo.bjl")
   
    lbl_clv_titolo.Text = titolo
   
    'Per immagine
    #if B4i
        foto.Put(img_foto, Starter.variabile1&name_image)
    #else if B4A  
        Starter.mappa_foto.Put(img_dettagli, foto)
    #else if B4J
        mappa_foto.Put(img_clv_ricordo, foto) ' <---------------------------------------HERE
    #End If
   
    Return p
   
End Sub

Where i wrong ?
Thank you
Marco
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The only reason to use ImageDownloader is for its (very basic) caching. For it to work, you shouldn't initialize ImageDownloader every download. Initialize it once and reuse it.
In the past it was simpler to use ImageDownloader than making the download yourself. With the resumable subs feature it is really trivial to download an image and set it to an ImageView.
 
Upvote 0
Top