Android Question load image in listview from url link

Adilson Jacinto

Active Member
Licensed User
Longtime User
Hi Erel,

I 'm trying to load a image from a url but I'm unable to do it so, I don't want to download an image from url just want to display it, is there a way of doing it?

I'm using B4a...

Thanks
 

Adilson Jacinto

Active Member
Licensed User
Longtime User
dim and initialize the list before the loop. Add all urls to download to the list in your loop. After your loop: Get the first item from the list and create a job and start the download. In Jobdone you save the file, remove the first item from the list.

then

Get the first item from the list and create a job and start the download. In Jobdone you save the file, remove the first item from the list.

and for all the rest of the list do the same
dim and initialize the list before the loop. Add all urls to download to the list in your loop. After your loop: Get the first item from the list and create a job and start the download. In Jobdone you save the file, remove the first item from the list.

then

Get the first item from the list and create a job and start the download. In Jobdone you save the file, remove the first item from the list.

and for all the rest of the list do the same

I tried to follow what you said, am I in the right direction?

B4X:
job3.Initialize("Job3", Me)
Dim cSalonName As Int = 5
Dim cSalonAddress As Int = 8
Dim cSalonIcon As Int = 3

For i = 0 To Lsalon.RowCount - 1
        Lsalon.Position = i
    salonName = Lsalon.GetString(cSalonName)
    salonAddress = Lsalon.GetString(cSalonAddress)
        job3.Tag = Lsalon.GetString(cSalonIcon)      

job3.Download("http://67.205.112.152/~iqueue/SalonAppIcons/" & Lsalon.GetString(cSalonIcon))
      Next

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      Select Job.JobName
         Case "Job3"
            'show the downloaded image
salon_listView.AddTwoLinesAndBitmap(salonName,salonAddress, job3.GetBitmap)
      End Select
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
  'Job.Release
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I tried to follow what you said, am I in the right direction?
where are you adding the urls to a list? where do you download the 1st item from the list? Where do you remove the first item from the list after downloading? Where are you downloading the next one?

Your code is wrong. EACH(!!!) httpjob must be dimmed and initialized. DONT RESUSE the same job!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Dim cSalonName As Int = 5
Dim cSalonAddress As Int = 8
Dim cSalonIcon As Int = 3

For i = 0 To Lsalon.RowCount - 1
        Lsalon.Position = i
    salonName = Lsalon.GetString(cSalonName)
    salonAddress = Lsalon.GetString(cSalonAddress)
        job3.Tag = Lsalon.GetString(cSalonIcon)    

dim job3 as httpjob
Job3.Initialize("Job3", Me)
job3.Download("http://67.205.112.152/~iqueue/SalonAppIcons/" & Lsalon.GetString(cSalonIcon))
      Next

I showed this earlier. NOTE that you are starting 100 jobs at once if your database give 100 results...

I showed a link where you should have looked in to get inspiration on how to start one job after the other. See here (again).
 
Upvote 0

Adilson Jacinto

Active Member
Licensed User
Longtime User
B4X:
Dim cSalonName As Int = 5
Dim cSalonAddress As Int = 8
Dim cSalonIcon As Int = 3

For i = 0 To Lsalon.RowCount - 1
        Lsalon.Position = i
    salonName = Lsalon.GetString(cSalonName)
    salonAddress = Lsalon.GetString(cSalonAddress)
        job3.Tag = Lsalon.GetString(cSalonIcon)   

dim job3 as httpjob
Job3.Initialize("Job3", Me)
job3.Download("http://67.205.112.152/~iqueue/SalonAppIcons/" & Lsalon.GetString(cSalonIcon))
      Next

I showed this earlier. NOTE that you are starting 100 jobs at once if your database give 100 results...

I showed a link where you should have looked in to get inspiration on how to start one job after the other. See here (again).


Hi DonManfred,

I have managed to successfully display the images with the appropriate name of the "salon", since I am using AddTwoLinesAndBitmap, for my second one I want to pass the address as second line, how do I do it so? please see image attached and code.

B4X:
  For i = 0 To Lsalon.RowCount - 1
            Lsalon.Position = i
            joblist.Add(Lsalon.GetString(cSalonIcon))
            salonName = Lsalon.GetString(cSalonName)
            salonAddress = Lsalon.GetString(cSalonAddress)
            ' Now we get the first item in this list and start download with ftp
            ExecuteRemoteQuery(joblist.Get(i),salonName)
      Next

Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.download("http://67.205.112.152/~iqueue/SalonAppIcons/" & Query)
End Sub

Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    ' Delete the topmost job in ftpjobs
    If joblist.Size > 0 Then
        joblist.RemoveAt(0)
    End If

    If Job.Success Then
        Dim res As String
        res = Job.GetString
       
        Dim resmap As Map
        resmap.Initialize
        resmap.Put("Job",Job)
        resmap.Put("Success",Job.Success)
        resmap.Put("Result",Job.GetString)
        jobresults.Add(resmap)
        salon_listView.AddTwoLinesAndBitmap(Job.JobName, "here I need the address" , Job.GetBitmap)
        salon_listView.SetSelection(salon_listView.Size-1)   

    Else
        Dim resmap As Map
        resmap.Initialize
        resmap.Put("Job",Job)
        resmap.Put("Success",Job.Success)
        resmap.Put("Exception","Error: " & Job.ErrorMessage)
        jobresults.Add(resmap)
        salon_listView.AddTwoLines(Job.JobName, Job.ErrorMessage)
        salon_listView.SetSelection(salon_listView.Size-1)   
        'ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub


Thanks
 

Attachments

  • scr.png
    scr.png
    83.1 KB · Views: 401
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I have managed to successfully display the images with the appropriate name of the "salon", since I am using AddTwoLinesAndBitmap, for my second one I want to pass the address as second line, how do I do it so? please see image attached and code.
maybe i did not understand correctly what you want to archieve

B4X:
salon_listView.AddTwoLinesAndBitmap("Line 1 text", "line 2 text" , Job.GetBitmap)
 
Upvote 0

Adilson Jacinto

Active Member
Licensed User
Longtime User
maybe i did not understand correctly what you want to archieve

B4X:
salon_listView.AddTwoLinesAndBitmap("Line 1 text", "line 2 text" , Job.GetBitmap)

Ok, let me explain again...

I am getting the address from the loop and
salon_listView.AddTwoLinesAndBitmap("Line 1 text", "line 2 text" , Job.GetBitmap) is in the JobDone function, so there is no way I will be able to pass the address because the jobdone only fires after the loop and at that point the addresses won't be called again. am I making sense?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
maybe

B4X:
Sub ExecuteRemoteQuery(Query As String, JobName As String, url as string)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.tag = url
    job.download("http://67.205.112.152/~iqueue/SalonAppIcons/" & Query)
End Sub
and then you can get the url from Job.Tag in jobdone...
 
Upvote 0

Adilson Jacinto

Active Member
Licensed User
Longtime User
maybe

B4X:
Sub ExecuteRemoteQuery(Query As String, JobName As String, url as string)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.tag = url
    job.download("http://67.205.112.152/~iqueue/SalonAppIcons/" & Query)
End Sub
and then you can get the url from Job.Tag in jobdone...


Excellent it worked :) :)

Thanks a lot for everything
 
Upvote 0
Top