iOS Question Help for CustomListView

Discussion in 'iOS Questions' started by ciginfo, Mar 14, 2015.

  1. ciginfo

    ciginfo Active Member Licensed User

    Hi,
    I have a CustomListView with in every item, an imageview, and 3 labels. (See the attached view)
    I have to load items from a database on a server, and I use JobDone.
    In the database there is the data for labels and th URL for image to load into the Imageview
    (URL_Vignette)
    .
    I Know to load an image from server to a Page.
    I Know and arrive to load the labels to CustomListView items but I do not arrive to load Image in the same item.
    Below my code when I load the same image from File.DirAssets. But I have to load a different image from the database to every item. Can someone help me?
    Thank you very much.

    Code:
    Sub JobDone (Job As HttpJob)
        
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
        
    If Job.Success = True Then           
       
        
    Select Job.JobName
            
    'XXXXXXXXX LISTING XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            Case LISTING_LIST
       
                
    Dim RES As String
                RES = Job.GetString
               
                
    Dim parser As JSONParser
                parser.Initialize(RES)
                
    Dim Affiche_list As List
                Affiche_list = parser.NextArray 
    'returns a list with maps
                    For i = 0 To Affiche_list.Size - 1
                        
    Dim sb As StringBuilder
                        
    Dim M As Map
                        M = Affiche_list.Get(i)
                        
    Dim   Civilite, Prenom, Ville, Zip, Telephone, sexe, URL_Vignette As String
                        
    Dim Longi, Lati As Double
                        
    Dim annee As Long
                        Civilite = M.Get(
    "civilite")
                        Prenom = M.Get(
    "prenom")
                        Ville = M.Get(
    "ville")
                        Zip = M.Get(
    "zip")
                        annee = M.Get(
    "annee")
                        sexe = M.Get(
    "sexe")
                        URL_Vignette = M.Get(
    "img")
                        Telephone = M.Get(
    "phone1")
                        Longi = M.Get(
    "longitude")
                        Lati = M.Get(
    "latitude")
                       
                        
    '----- Pour le GPS ------------------------------------
                        Dim distance As Double
                        
    Dim TheDistance, MyDistance, Carte_V As String
                        
    Dim TheLongitude, TheLatitude As Double
                        TheLongitude = Longi
                        TheLatitude = Lati
                        
    Dim Location1, Location2 As  Location
                        Location1.Initialize2(LatitudeMe, LongitudeMe)
                        Location2.Initialize2(TheLatitude, TheLongitude)
                        distance = Location1.DistanceTo(Location2)
    'Distance en metres entre location1 et location2
                        distance = distance / 1000
                        
    'distance = Round2 (distance,1)'Dans B4A
                        TheDistance = NumberFormat(distance,0,1)'Dans B4i
                        Carte_V = Civilite & " " & Prenom & ", " & annee
                       
                        
    'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                       
                        
    'HOW TO ADD HERE CODE FOR THE VIGNETTE IMAGE
                       
                        
    'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                       
                        
    Dim Rien = "" As String
                        
    Dim MyVignette As String
                        MyVignette = 
    "kinda.png"
                           
                        
    If GeoLoc = True Then
                                    MyDistance = 
    "A " & TheDistance & " km" & ", " & Ville
                            clvListing.Add(CreateListItem3(Carte_V, MyDistance, Ville, MyVignette,clvListing.AsView.Width, 
    55dip), 70dip, M)
                        
    Else
                            clvListing.Add(CreateListItem3(Prenom, Ville,Rien, MyVignette, clvListing.AsView.Width, 
    55dip), 70dip, M)
                        
    End If       
                    
    Next
            
    Case "JobImgEcran"
                    
    'show the downloaded image
                    ImgEcran.Bitmap = Job.GetBitmap   
            
    End Select
           
        
    Else
            
    Log("Error: " & Job.ErrorMessage)
            hd.ToastMessageShow(
    "Error: " & Job.ErrorMessage, True)
        
    End If
        Job.Release
    End Sub
    Code:
    Sub CreateListItem3(Text1 As String, Text2 As String, Text3 As String,Vignette As String, Width As Int, Height As Int) As Panel
         
    'Routine pour placer 3 labels et une vignette dans l'item de la customListView
        Dim P As Panel
        P.Initialize(
    "")
        P.Color = 
    Colors.White
        
    'Dim ImgVignette As ImageView
        Dim lbl1, lbl2, lbl3 As Label
       
        lbl1.Initialize(
    "lbl1")
        lbl1.TextAlignment = lbl1.ALIGNMENT_LEFT
        
    'lbl1.Color =Colors.Gray
        lbl1.Text = Text1
        lbl1.Font = 
    Font.CreateNew(22)
       
        lbl2.Initialize(
    "lbl2")
        lbl2.TextAlignment = lbl2.ALIGNMENT_LEFT
        lbl2.Multiline= 
    True
        lbl2.Text = Text2
        lbl2.Font = 
    Font.CreateNew(16)
       
        lbl3.Initialize(
    "lbl3")
        lbl3.TextAlignment = lbl2.ALIGNMENT_LEFT
        lbl3.Multiline= 
    True
        lbl3.Text = Text3
        lbl3.Font = 
    Font.CreateNew(16)
       
        
    'JobImgEcran.Initialize("JobImgEcran", Me)
        'JobImgEcran.Download(MyURL_Image)
        Dim ImgVignette As ImageView
        ImgVignette.Initialize(
    "ImgVignette")
        
    Dim Repertoire = File.DirAssets As String
       
       
        ImgVignette.Bitmap = 
    LoadBitmap(Repertoire , Vignette)
       
       
        P.AddView(ImgVignette, 
    2dip5dip18%x18%x )
        P.AddView(lbl1, 
    5dip + 20%x0dip75%x, Height/2-5dip )
        P.AddView(lbl2, 
    5dip + 20%x, lbl1.Height, 75%x, Height/2)
        P.AddView(lbl3, 
    5dip + 20%x, (lbl1.Height +lbl2.Height)-5dip75%x, Height/2)
        
    Return P
    End Sub
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    1. Create the item without any image.
    2. Send a new HttpJob for each image url and set Job.Tag to point to the target ImageView. Now in JobDone check the job name and based on it assign the image to the ImageView.
     
  3. ciginfo

    ciginfo Active Member Licensed User

    Thank you Erel for your answer, but I don't uderstand very well. In the attached project I have made an example which works fine, but without image loaded from the database, only the same image loaded from File.DirAssets. I know you have much work but can you explain me modifing my example attached to obtain different image for every item from my database. The variable which contains the Url of the image in the database is "img" :
    URL_Vignette = M.Get("img").
    A Great Thank you!!!
     

    Attached Files:

  4. Erel

    Erel Administrator Staff Member Licensed User

  5. ciginfo

    ciginfo Active Member Licensed User

    I use now ImageDownLoader, but why in the code above, image is loaded only into the last item of the CustomListView?
    Thank you

    Code:
    'Code module
    #Region  Project Attributes
        
    #ApplicationLabel: B4i Example
        
    #Version: 1.0.0
        
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
        #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
        
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #End Region

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'Public variables can be accessed from all modules.
        Public App As Application
        
    Public NavControl As NavigationController
        
    Private Page1, Listing As Page
        
    Dim clvListing As CustomListView
        
    Private Downloader As ImageDownloader
      
        
    Dim JobVignette As HttpJob
        
    Private hd As HUD
        
    Private LISTING_LIST = "listing_list" As String
        
    Dim mapData As Map
    End Sub

    Private Sub Application_Start (Nav As NavigationController)
        NavControl = Nav
        Listing.Initialize(
    "Listing")
        Listing.RootPanel.LoadLayout(
    "Listing")
        Listing.RootPanel.Color = 
    Colors.ARGB(255,109,237,199)'(255,255,0,0)
        Listing.Title = "Listing"
        clvListing.Initialize(Me, 
    "clvListing"100%x)
        Listing.RootPanel.AddView(clvListing.AsView, 
    05dip100%x100%y)

        
    '-----------------------------------------------------------------------------
        ExtraitListePardistance 'job  
        NavControl.ShowPage(Listing)
      
    End Sub
    Sub ExecuteRemoteQuery(Query As String, JobName As String)
        
    Dim job As HttpJob
        job.Initialize(JobName, Me)
        job.PostString(
    "http://www.xxxxxxxxxxx.com/xxxxxxxxxxxx/connection.php", Query)'Chez OVH Kindabreak
    End Sub
    Sub ExtraitListePardistance
        ExecuteRemoteQuery(
    "SELECT ID, date_du_jour, mail1, civilite, nom, prenom, sexe, annee, adresse1, zip, ville, phone1, phone2, nationalite, profession, longitude, latitude, datedebut, datefin, facebook, motor, tarif, texte, img FROM kindasitters ",LISTING_LIST)

    End Sub
    Sub JobDone (Job As HttpJob)
        
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
        
    If Job.Success = True Then              
        
    Select Job.JobName
            
    'XXXXXXXXX LISTING XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            Case LISTING_LIST
      
                
    Dim RES, RES2 As String
                RES = Job.GetString
                
    Dim parser As JSONParser
                parser.Initialize(RES)
                
    Dim Affiche_list As List
                Affiche_list = parser.NextArray 
    'returns a list with maps
                    For i = 0 To Affiche_list.Size - 1
                        
    Dim sb As StringBuilder
                        
    Dim M As Map
                        M = Affiche_list.Get(i)
                        
    Dim   Civilite, Nom, Prenom, Ville, Zip, Telephone, sexe, URL_Vignette As String
                        Civilite = M.Get(
    "civilite")
                        Prenom = M.Get(
    "prenom")
                        Ville = M.Get(
    "ville")
                        Zip = M.Get(
    "zip")
                      
                        sexe = M.Get(
    "sexe")
                        URL_Vignette = M.Get(
    "img")
                        Telephone = M.Get(
    "phone1")
                        
    Dim Carte_V, TheAdress, MyVignette As String
                        Carte_V =  Prenom & 
    ", " & Nom
                        TheAdress = Ville & 
    ", " & Zip
                      

                        clvListing.Add(CreateListItem3(Prenom, Ville,TheAdress, URL_Vignette, clvListing.AsView.Width, 
    55dip), 70dip, M)
                              
                    
    Next
        
    End Select
          
        
    Else
            
    Log("Error: " & Job.ErrorMessage)
            hd.ToastMessageShow(
    "Error: " & Job.ErrorMessage, True)
        
    End If
        Job.Release
    End Sub
    Sub CreateListItem3(Text1 As String, Text2 As String, Text3 As String, ImgPath As String, Width As Int, Height As Int) As Panel
         
    'Routine pour placer 2 labels dans l'item de la customListView
        Dim P As Panel
        P.Initialize(
    "")
        P.Color = 
    Colors.White
        
    'Dim ImgVignette As ImageView
        Dim lbl1, lbl2, lbl3 As Label
      
        lbl1.Initialize(
    "lbl1")
        lbl1.TextAlignment = lbl1.ALIGNMENT_LEFT
        
    'lbl1.Color =Colors.Gray
        lbl1.Text = Text1
        lbl1.Font = 
    Font.CreateNew(22)
      
        lbl2.Initialize(
    "lbl2")
        lbl2.TextAlignment = lbl2.ALIGNMENT_LEFT
        lbl2.Multiline= 
    True
        lbl2.Text = Text2
        lbl2.Font = 
    Font.CreateNew(16)
      
        lbl3.Initialize(
    "lbl3")
        lbl3.TextAlignment = lbl2.ALIGNMENT_LEFT
        lbl3.Multiline= 
    True
        lbl3.Text = Text3
        lbl3.Font = 
    Font.CreateNew(16)

        
    Dim ImgVignette As ImageView
        ImgVignette.Initialize
        Downloader.Initialize
        Downloader.Download(CreateMap(ImgVignette: ImgPath))
      
      
      
        P.AddView(ImgVignette, 
    10dip5dip15%x15%x )
        P.AddView(lbl1, 
    5dip + 20%x0dip75%x, Height/2-5dip )
        P.AddView(lbl2, 
    5dip + 20%x, lbl1.Height, 75%x, Height/2)
        P.AddView(lbl3, 
    5dip + 20%x, (lbl1.Height +lbl2.Height)-5dip75%x, Height/2)
        
    Return P
    End Sub
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Don't initialize Downloader multiple times. Initialize it once and then call Download whenever you need.
     
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