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
 

DonManfred

Expert
Licensed User
Longtime User
doenload the image with httputils and save it to sdcard after download.
Load the image then into a bitmap to add it to your listview.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Adilson Jacinto

Active Member
Licensed User
Longtime User
Ok I will have a look at them, thanks
Unfortunately I did't find the answer I was looking for. Basic here is my code..

Dim Lsalon As ResultSet

Lsalon = mh1.Query("SELECT * FROM IQBSalons WHERE SalonOnStop <> 'Y'")
If Lsalon.IsInitialized=False Then
Msgbox("Records Not Found","Warning")
Return
Else
For i = 0 To Lsalon.RowCount - 1

Dim cSalonName As Int
Dim cSalonAddress As Int
Dim cSalonIcon As Int
cSalonName=5
cSalonAddress=8
cSalonIcon=3
Lsalon.Position = i

job3.Download("http://xx.xxx.xxx.xxx/xxxx/SalonAppIcons/" & Lsalon.GetString(cSalonIcon))
salonName = Lsalon.GetString(cSalonName)
salonAddress = Lsalon.GetString(cSalonAddress)



salon_listView.AddTwoLinesAndBitmap(salonName,salonAddress, "Here is where i need to get the image!!!")

Next
End If


I even tried to add to the list after the loop but if if do it that way it will repeat the last record because the JobDone only fires after the loop

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, job.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
Please use code tags when posting code! Sources are HARD TO READ without using code-tags

Upload your project as zip is the best way to show us your code.

maybe you need to strip down your code to have an example you can upload (if your code is private)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I even tried to add to the list after the loop but if if do it that way it will repeat the last record because the JobDone only fires after the loop
No. If you do it right it will work.
EACH httpjob needs to be DIMmed and intialized. You CAN NOT reuse a job you already using.

B4X:
For i = 0 To Lsalon.RowCount - 1
    Dim cSalonName As Int = 5
    Dim cSalonAddress As Int = 8
    Dim cSalonIcon As Int = 3
    Lsalon.Position = i
    dim job3 as httpjob
    job3.initialize("Job3",me)   
    job3.Tag = Lsalon.GetString(cSalonIcon)
    job3.Download("http://xx.xxx.xxx.xxx/xxxx/SalonAppIcons/" & Lsalon.GetString(cSalonIcon))
next
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
BUT. You should use a global list for all jobs and execute them one after one. The code i posted will create
Lsalon.RowCount - 1 jobs and all will be started parallel

I suggest to first learn how to work with httputils using ONE JOB, ONE download, ONE image which you want to save...

If this is working you can go on.

Dont expect that i´ll do the work for you as you can find HUNDRETS of examples in forum forum.
 
Upvote 0

Adilson Jacinto

Active Member
Licensed User
Longtime User
No. If you do it right it will work.
EACH httpjob needs to be DIMmed and intialized. You CAN NOT reuse a job you already using.

B4X:
For i = 0 To Lsalon.RowCount - 1
    Dim cSalonName As Int = 5
    Dim cSalonAddress As Int = 8
    Dim cSalonIcon As Int = 3
    Lsalon.Position = i
    dim job3 as httpjob
    job3.initialize("Job3",me)  
    job3.Tag = Lsalon.GetString(cSalonIcon)
    job3.Download("http://xx.xxx.xxx.xxx/xxxx/SalonAppIcons/" & Lsalon.GetString(cSalonIcon))
next


And then How do I add to the list in the same loop?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
And then How do I add to the list in the same loop?
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
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
any luck there?
No. I´m not able to get your code running.
I dont have access to the database.
I even dont have the needed mysql library installed.

I decribed the way to go here. You can find an example of this solution here.

I wrote it earlier:
Dont expect that i´ll do the work for you as you can find HUNDRETS of examples in forum
 
Upvote 0

Adilson Jacinto

Active Member
Licensed User
Longtime User

Hi Erel, the example you provided me don't really suit me... :(

Why can't I use this:

For i = 0 To Lsalon.RowCount - 1
Lsalon.Position = i
Dim cSalonName As Int = 5
Dim cSalonAddress As Int = 8
Dim cSalonIcon As Int = 3
imghidden.Visible = True
ImageView1.Visible = True
salonName = Lsalon.GetString(cSalonName)
salonAddress = Lsalon.GetString(cSalonAddress)
Dim links As Map
links.Initialize
links.Put(ImageView1, "http://xx.xxx.xx.x/xxx/SalonAppIcons/" & Lsalon.GetString(cSalonIcon))

CallSubDelayed2(imgDownloader, "Download", links)
salon_listView.AddTwoLinesAndBitmap(salonName,salonAddress, ImageView1)
Next
End If
 
Upvote 0
Top