Android Question How would one Ioad images into a cxCustomView from the internet

sdixon

Member
Licensed User
Longtime User
I am filling a cxCustomView using clvExpandable

When II start the app, I download a json file containing all the information I need to fill each item I need to display.

B4X:
DownloadAndSaveFile(f.msFilePSA, "psa.json")
.
.
Sub DownloadAndSaveFile (Link As String, FName As String)
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(Link)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim out As OutputStream = File.OpenOutput(File.DirInternal, FName, False)
        File.Copy2(j.GetInputStream, out)
        out.Close '<------ very important
    End If
    j.Release
End Sub

I then cycle through the MAP I created when I parsed the json file.

B4X:
For Each k As String In f.PSAMap.Keys       
        m = f.PSAMap.Get(k)
        If aLang = "EN" Then
            Title = m.Get("psaTitleEN")
        Else
            Title = m.Get("psaTitleID")
        End If       
        Dim p As B4XView = CreateItem(Rnd(0xFF000000, 0xFFFFFFFF), Title, 400dip)
        p.Tag = m.Get("psaUrlEN")
        imgListing.Height = 60dip
        imgListing.Top = 0dip
        imgListing.SetBitmap(LoadBitmap(File.DIRASSETS , "icon_48x48.png"))
        lblItemTitle.Text = Title       
        cvPremium.Add(p, exPand.CreateValue(p, "some value"))
        GetItemImage(m.Get("psaImage"))
        lblItemBody.Text = m.Get("psaMessageEN")
        lblItemBody.Top = imgItem.Top
        lblItemBody.Height = imgItem.Height
        lblItemUrl.Top = imgItem.Top + imgItem.Height
        lblItemUrl.Text = m.Get("psaUrlEN")
        pnlExpanded.Visible = True
        Next

I get the image with

GetItemImage(m.Get("psaImage"))

B4X:
Sub GetItemImage(ImageUrl As String)
    Dim ItemImage As HttpJob
    ItemImage.Initialize("ItemImage", Me)
    ItemImage.Download(ImageUrl)
End Sub

B4X:
Sub JobDone (Job As HttpJob)
    'Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "ItemImage"
                imgItem.SetBitmap(Job.GetBitmapResize(imgItem.Width, imgItem.Height, True))
        End Select
    Else
        Msgbox2Async("Error: " & f.msNoInternet, f.msNetworkProblem, f.msBtnOK, "", "", LoadBitmap(File.DirAssets, f.msInternalImage), False)
        Wait For Msgbox_Result (Result As Int)
        If Result = DialogResponse.POSITIVE Then
            Activity.Finish
            ExitApplication
        End If
    End If
    Job.Release
End Sub

Every text label appears in it proper place. Tile is right per item, text and url labels are filled properly, but the images are all blank except for the last one which contains the first image available in the json file

What am I doing wrong here

Thanks in advance.
 

sdixon

Member
Licensed User
Longtime User
What is cxCustomView? Why are you using JobDone sub?
my apologies - xCustomView.
Because I don't know any better.
 
Upvote 0

sdixon

Member
Licensed User
Longtime User
What is cxCustomView? Why are you using JobDone sub?
If I knew better I probably would not have used JobDone, but the forums contain so much information that after two days of fruitless searching the frustration says "Try Something" Well I tried something and it's not working so I am asking for help to get it working. And if I misspell something in the process, my deepest apologies.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

sdixon

Member
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…