Android Question Imagedownloader and lazyloading

Sasuke Sama

Active Member
Licensed User
Hi
Can someone give me a small project or example of combining them as one? I've been trying but with no luck
I have a larg json with over 900 images and using the imagedownloader alone makes the app lagging as hell XD
Thanx
 

Brandsum

Well-Known Member
Licensed User
You are loading the clv inside an imageview ? as far as i understood.
i mean i have the imageview inside a layout with other views like labels and i want to load that layout inside the clv
For a quick illustration, I added imageviews inside a clv. If you want to load a layout having imageview then just search for that imageview inside visible panels like this,
B4X:
For i = FirstIndex To LastIndex
    Dim p As Panel = CLV.GetPanel(i)
    For Each v As View In p.GetAllViewsRecursive
        If v Is ImageView Then
            Dim iv As ImageView = v
            If iv.Bitmap = Null Then
                links.Put(iv, iv.Tag)
            End If
        End If
    Next
Next
 

Sasuke Sama

Active Member
Licensed User
For a quick illustration, I added imageviews inside a clv. If you want to load a layout having imageview then just search for that imageview inside visible panels like this,
B4X:
For i = FirstIndex To LastIndex
    Dim p As Panel = CLV.GetPanel(i)
    For Each v As View In p.GetAllViewsRecursive
        If v Is ImageView Then
            Dim iv As ImageView = v
            If iv.Bitmap = Null Then
                links.Put(iv, iv.Tag)
            End If
        End If
    Next
Next
Im tired :(
This dosent work
B4X:
Sub CLV_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Dim links As Map
    links.Initialize
    For i = FirstIndex To LastIndex
        Dim p As Panel = clv.GetPanel(i)
        For Each v As View In p.GetAllViewsRecursive
            If v Is ImageView Then
                Dim iv As ImageView = v
                If iv.Bitmap = Null Then
                    links.Put(iv, "https://images.wallpaperscraft.com/image/tree_fog_grass_119819_800x600.jpg")
                End If
            End If
        Next
    Next
    CallSubDelayed2(ImageDownloader, "Download", links)
End Sub

i use this code to load the items in the clv

B4X:
    For i=0 To imglinks.Size-5
Dim p As Panel
p.Initialize("p")
p.LoadLayout("card1")
p.SetLayout(0,0,Activity.Width,180dip)
        clv.Add(p,"")
    Next
items loads fine but no images

sorry in advance and thank you
 

Sasuke Sama

Active Member
Licensed User
For a quick illustration, I added imageviews inside a clv. If you want to load a layout having imageview then just search for that imageview inside visible panels like this,
B4X:
For i = FirstIndex To LastIndex
    Dim p As Panel = CLV.GetPanel(i)
    For Each v As View In p.GetAllViewsRecursive
        If v Is ImageView Then
            Dim iv As ImageView = v
            If iv.Bitmap = Null Then
                links.Put(iv, iv.Tag)
            End If
        End If
    Next
Next
Got it work thank you sooooooooooooo much
 

Sasuke Sama

Active Member
Licensed User
For a quick illustration, I added imageviews inside a clv. If you want to load a layout having imageview then just search for that imageview inside visible panels like this,
B4X:
For i = FirstIndex To LastIndex
    Dim p As Panel = CLV.GetPanel(i)
    For Each v As View In p.GetAllViewsRecursive
        If v Is ImageView Then
            Dim iv As ImageView = v
            If iv.Bitmap = Null Then
                links.Put(iv, iv.Tag)
            End If
        End If
    Next
Next
one last question sir
how can i remove the unvisable panels with this code?
B4X:
            'not visible
            If p.NumberOfViews > 0 Then
                p.RemoveAllViews '<--- remove the layout
            End If
im trying to add it to your code but it gives me a blank list
thank you so much
 

Brandsum

Well-Known Member
Licensed User
one last question sir
how can i remove the unvisable panels with this code?
B4X:
            'not visible
            If p.NumberOfViews > 0 Then
                p.RemoveAllViews '<--- remove the layout
            End If
im trying to add it to your code but it gives me a blank list
thank you so much
Didn't understand your query. Do you want to remove the panels which are above/below the visible screen? Then you have to reload that layout again when those become visible, and this will consume more CPU and internet data as those images will be downloaded again.
 

Sasuke Sama

Active Member
Licensed User
Didn't understand your query. Do you want to remove the panels which are above/below the visible screen? Then you have to reload that layout again when those become visible, and this will consume more CPU and internet data as those images will be downloaded again.
Yes that is what i want to do
As far as the lazyloading example says removing invisible panels will make the app faster to load larg lists
 

Brandsum

Well-Known Member
Licensed User
Then while creating the list instead of loading the layout, set all the data as a map or custom type to the value of clv item. Load the layout after this line
B4X:
Dim p As Panel = clv.GetPanel(i)
and set your data.

And remove all the views of a clv item if that is out of the visible bound (less than FirstIndex or greater LastIndex)
 
Last edited:
Top