Android Question Show online images - help me to understand

tsteward

Well-Known Member
Licensed User
Longtime User
Hello all those smarter than me.
I want to present my users with a list of images (thumbnails) where they will see all images in a given directory. Select one & return its url to my app.

I found this app by erel but I don't understand how it works and can't get it to display my images.
my images are at https://www.locksdownunder.com/LaraImages/uploads/

I just don't get it or is there a better way?
Yes i've searched but cant really find what i need

Thank You

B4X:
Sub Globals
    Private CustomListView1 As CustomListView
    Private PCLV As PreoptimizedCLV
    Private xui As XUI
    Private Label1 As B4XView
    Type MyImageData (IndexOfFirstImage As Int)
End Sub


Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    PCLV.Initialize(Me, "PCLV", CustomListView1)
    For i = 1 To 600 Step 4
        PCLV.AddItem(150dip, xui.Color_White, CreateMyImageData(i))
    Next
    PCLV.ShowScrollBar = False 'no fast scrolling
    PCLV.ExtraItems = 5
    PCLV.Commit
End Sub

Sub CustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
        Dim item As CLVItem = CustomListView1.GetRawListItem(i)
        Dim pnl As B4XView = xui.CreatePanel("")
        item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
        Dim data As MyImageData = item.Value
        'Create the item layout
        pnl.LoadLayout("Item")
        For i = 0 To 3
            pnl.GetView(0).GetView(i + 4).Text = data.IndexOfFirstImage + i
            DownloadAndSetImage($"https://i.picsum.photos/id/${data.IndexOfFirstImage + i}/200/300.jpg"$, pnl.GetView(0).GetView(i))
        Next
    Next
End Sub

Sub DownloadAndSetImage(Url As String, ImageView As B4XView)
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(Url)
    Wait For (j) JobDone (j As HttpJob)
    If j.Success Then
        Try
            If ImageView.Parent.Parent.IsInitialized Then
                Dim bmp As B4XBitmap = j.GetBitmapResize(ImageView.Width, ImageView.Height, True)
                ImageView.SetBitmap(bmp)
            End If
        Catch
            Log(LastException)
        End Try
    End If
    j.Release
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Public Sub CreateMyImageData (IndexOfFirstImage As Int) As MyImageData
    Dim t1 As MyImageData
    t1.Initialize
    t1.IndexOfFirstImage = IndexOfFirstImage
    Return t1
End Sub
 
Last edited:

AnandGupta

Expert
Licensed User
Longtime User
Hell all those smarter than me.
Now, now. Are you angry with members 'smarter than you' ?
Why should you send them to Hell !

I know, I know you missed one 'o' :D
Also your given link is wrong.

There are some examples on CLV where images are listed from online Flicker or GDrive etc.
Erel also given a grid of images example from online photos.

You may check them, if it helps.

Regards,

Anand
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Now, now. Are you angry with members 'smarter than you' ?
Why should you send them to Hell !

I know, I know you missed one 'o' :D
Also your given link is wrong.

There are some examples on CLV where images are listed from online Flicker or GDrive etc.
Erel also given a grid of images example from online photos.

You may check them, if it helps.

Regards,

Anand
yeah i have checked them and putting my image directory in didnt work
the attached code seems very simple and very quick just cant get it to show my images
here is direct link to one image https://www.locksdownunder.com/LaraImages/uploads/1010-1108.jpg
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I guess you are refering to this example:

DownloadAndSetImage($"https://i.picsum.photos/id/${data.IndexOfFirstImage + i}/200/300.jpg"$, pnl.GetView(0).GetView(i))
Try adding .Tag:
B4X:
DownloadAndSetImage($"https://i.picsum.photos/id/${data.IndexOfFirstImage + i}/200/300.jpg"$, pnl.GetView(0).GetView(i).Tag)
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Here is my attempt. I am not really like cats but... just using a test API. ?

pclv-demo.jpg
 

Attachments

  • PCLV.zip
    23.3 KB · Views: 301
Upvote 0
Top