Android Question Load Image From Server To ImageView

taylorw

Active Member
Licensed User
Hi all,now i using a customlistview and i need to load image to imageview from my server.
But i try using this code,but it seen like can't load image to the right imageview.
B4X:
Sub Display_Image
    Dim links As Map
   
    If Load_Last_Image_Index < ListView_Order.GetSize Then
        For i = Load_Last_Image_Index To ListView_Order.GetSize -1
            Dim pnl As Panel = ListView_Order.GetPanel(i)
            Dim Get_Path  As Label = pnl.GetView(7)
            Dim Get_Image_View  As ImageView = pnl.GetView(2)
           
            If Get_Path.Text <> "" Then
                links.Initialize
                links.Put(Get_Image_View, "Server_Path" & Get_Path.Text & ".jpg")
               
            End If
        Next
       
        CallSubDelayed2(ImageDownloader, "Download", links)
    End If
    Load_Last_Image_Index = ListView_Order.GetSize
End Sub

B4X:
Sub Download (ImageViewsMap As Map)
    For i = 0 To ImageViewsMap.Size - 1
        tasks.Put(ImageViewsMap.GetKeyAt(i), ImageViewsMap.GetValueAt(i))
        Dim link As String = ImageViewsMap.GetValueAt(i)
            ongoingTasks.Put(link, "")
            Dim j As HttpJob
            j.Initialize(link, Me)
            j.Download(link)
    Next
End Sub

B4X:
Sub JobDone(Job As HttpJob)
    ongoingTasks.Remove(Job.JobName)
    If Job.Success Then
        Dim bmp As Bitmap = Job.GetBitmap
        cache.Put(Job.JobName, bmp)
        If tasks.IsInitialized Then
            For i = 0 To tasks.Size - 1
                Dim link As String = tasks.GetValueAt(i)
                If link = Job.JobName Then
                    Dim iv As ImageView = tasks.GetKeyAt(i)
                    iv.SetBackgroundImage(bmp)
                End If
            Next
        End If
    Else
        Log("Error downloading image: " & Job.JobName & CRLF & Job.ErrorMessage)
    End If
    Job.Release
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
From the snippets you posted i can not help.
Did you get any error??? WHICH error?

Upload a sample project which shows the problem. This would make it easier for us to help.
 
Upvote 0

taylorw

Active Member
Licensed User
Hi DonManfred, i did get any error.
And my sample project is here,In frmOrder.
 

Attachments

  • Smaple (2).zip
    351.8 KB · Views: 198
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Correct code:
B4X:
Sub JobDone(Job As HttpJob)
   ongoingTasks.Remove(Job.JobName)
   If Job.Success Then
     Dim bmp As Bitmap = Job.GetBitmap
     cache.Put(Job.JobName, bmp)
     If tasks.IsInitialized Then
       For i = 0 To tasks.Size - 1
         Dim link As String = tasks.GetValueAt(i)
         If link = Job.JobName Then
           Dim iv As ImageView = tasks.GetKeyAt(i)
           iv.SetBackgroundImage(bmp)
         End If
       Next
     End If
   Else
     Log("Error downloading image: " & Job.JobName & CRLF & Job.ErrorMessage)
   End If
   Job.Release
End Sub
 
Upvote 0
Top