Android Question load image in listview from url link

Discussion in 'Android Questions' started by Adilson Jacinto, Sep 2, 2015.

  1. Adilson Jacinto

    Adilson Jacinto Active Member Licensed 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
     
  2. DonManfred

    DonManfred Expert Licensed 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.
     
  3. Adilson Jacinto

    Adilson Jacinto Active Member Licensed User

    Is there a way that you could give me an code example?

    thanks
     
  4. DonManfred

    DonManfred Expert Licensed User

  5. Adilson Jacinto

    Adilson Jacinto Active Member Licensed User

  6. Adilson Jacinto

    Adilson Jacinto Active Member Licensed User

    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
     
  7. DonManfred

    DonManfred Expert Licensed 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)
     
  8. DonManfred

    DonManfred Expert Licensed 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.

    Code:
    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
     
  9. Adilson Jacinto

    Adilson Jacinto Active Member Licensed User

    if I upload my project there is a connection to the mysql database but is it ok to leve the username and password there?
     
  10. DonManfred

    DonManfred Expert Licensed 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.
     
  11. Adilson Jacinto

    Adilson Jacinto Active Member Licensed User


    And then How do I add to the list in the same loop?
     
  12. DonManfred

    DonManfred Expert Licensed User

    no.
     
  13. DonManfred

    DonManfred Expert Licensed 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
     
    Adilson Jacinto likes this.
  14. Adilson Jacinto

    Adilson Jacinto Active Member Licensed User

    I am trying to upload it but is saying it is too large, it is only 2.9 MB?
     
  15. DonManfred

    DonManfred Expert Licensed User

    What the hell did you zipped?

    In the ide call FILE->Export as zip. Upload this zip (it should be much smaller)
     
  16. Adilson Jacinto

    Adilson Jacinto Active Member Licensed User

    Ok, thanks, try this then
     

    Attached Files:

  17. Adilson Jacinto

    Adilson Jacinto Active Member Licensed User

    any luck there?
     
  18. DonManfred

    DonManfred Expert Licensed User

    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:
     
  19. Erel

    Erel Administrator Staff Member Licensed User

  20. Adilson Jacinto

    Adilson Jacinto Active Member Licensed 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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice