XML to Listview with Images

rosskennedyiv

New Member
Licensed User
Longtime User
I have a listview that is populated with a combination of text and banners. The text only lines always populate correctly. The lines that have the banners always show the last banner to get downloaded and it's link. Two questions:


  • How do I get it to show each banner and not the same banner over and over?

  • Also how do I get them to display in the correct order? Currently it shows all the text only items first then repeats the last banner the number of times a banner is present in the list.
Any help would be greatly appreciated. Thanks.
B4X:
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
    If parser.Parents.IndexOf("item") > -1 Then
        If Name = "title" Then
            Title = Text.ToString
        Else If Name = "link" Then
            Link = Text.ToString
        End If
    End If
    If parser.Parents.IndexOf("image") > -1 Then
        If Name = "title" Then
            Title = Text.ToString
        Else If Name = "link" Then
            Link = Text.ToString
      Else If Name = "url" Then
         lvImg = Text.ToString
        End If
    End If
   If Name = "image" Then
      job1.Initialize("JobGP",Me)
      job1.Download(lvImg)
      Return
   End If
   If Name = "item" Then
        lvPromo.AddSingleLine2(Title, Link) 
    End If
End Sub
Sub JobDone (Job As HttpJob)
   If Job.Success=True Then
      Select Job.JobName
         Case "JobGP"
            lvPromo.AddTwoLinesAndBitmap2(Title, Link, Job.GetBitmap, Link)
            lvPromo.TwoLinesAndBitmap.SecondLabel.Visible=False
            lvPromo.TwoLinesAndBitmap.Label.Visible=False
            lvPromo.TwoLinesAndBitmap.ImageView.Width=lvPromo.Width
      End Select
   End If
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should create a new Job object for each request. This is done by calling Dim again:
B4X:
If Name = "image" Then
 Dim job1 As HttpJob
        job1.Initialize("JobGP",Me)
        job1.Download(lvImg)
        Return
    End If

Your program will still not work correctly as you need to match the title and link to the image.

There are several ways to do it.
You can use a Map that maps between the Job object (key) to a custom type that holds the title and other values.

I recommend you to use CustomListView class instead of ListView. It will allow you to update the image when the image is available.
 
Upvote 0

rosskennedyiv

New Member
Licensed User
Longtime User
I like the Custom List View better and your suggestion works for getting the images correctly.

It some figuring out to get the httpJob TaskID. I am now able to use the Job taskID to find the MAP entry that has the link.

Thanks for your help. It works great.
 
Last edited:
Upvote 0
Top