Android Question (solved) How to Read Images from Sub-Folder in Dirinternal into Erel's SMM Example 2 Instead of Online

omo

Active Member
Licensed User
Longtime User
I tried reading pictures from local files in SMM example 2 thus:
B4X:
filenm2b = (List1.Get(x)) 'i should always take note in b4xtable or album.can be used for tag to identify each cell
filenm2b = filenm2b.SubString(filenm2b.LastIndexOf("/") + 1)

pnl.GetView(x).GetView(1).Text = filenm2b
MediaManager.SetMediaFromFile(pnl.GetView(x).GetView(0), xui.DefaultFolder, "myalbum2/"&filenm2b,"image/*", Null) 'l2 is a list of the files

I only get three images from folder being repeated as displayed below instead of displaying eight/nine different pictures available in the folder
as shown in the images below:
smm2.jpg


The sample code is attached below via Google Drive due to a bit Upload Limit:
SMM Example2
 
Solution
I've just went over your code. I see many mistakes.

Don't call ListFiles inside VisibleChanged event. List the files once and store the list.

B4X:
If Success Then
    For x = 0 To 2
        Dim t As Int = data.IndexOfFirstImage + x
        If t >= List1.Size Then
            Exit
        End If
        filenm2b = (List1.Get(x)) 'i should always take note in b4xtable or album.can be used for tag to identify each cell
        filenm2b = filenm2b.SubString(filenm2b.LastIndexOf("/") + 1)
        pnl.GetView(x).GetView(1).Text = filenm2b
        MediaManager.SetMediaFromFile(pnl.GetView(x).GetView(0), xui.DefaultFolder, "myalbum2/"&filenm2b,"image/*", Null) 'l2 is a list of the files
    Next
End If

filenm2b = (List1.Get(x))...

omo

Active Member
Licensed User
Longtime User
Don't try to list the assets files with File.ListFiles. It doesn't work.
Thank you so much, Erel. There are two File.ListFiles in the code, If i remove File.ListFiles in CustomListView1_VisibleRangeChanged, i get same result as earlier complained, but if i remove that of B4XPage_Created, i get blank page and list1 becomes empty and Files becomes unknown in the code below:
B4X:
Wait For (File.ListFilesAsync(xui.DefaultFolder&"/myalbum2")) Complete (Success As Boolean, Files As List)
    If Success Then
        For Each f As String In Files
            List1.Add(File.Combine(xui.DefaultFolder&"/myalbum2", f))
                    
        Next
'        'MsgboxAsync(List1.Get(0), List1.Get(1))
    End If
If i remove File.ListFiles, which code will i use to replace it?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've just went over your code. I see many mistakes.

Don't call ListFiles inside VisibleChanged event. List the files once and store the list.

B4X:
If Success Then
    For x = 0 To 2
        Dim t As Int = data.IndexOfFirstImage + x
        If t >= List1.Size Then
            Exit
        End If
        filenm2b = (List1.Get(x)) 'i should always take note in b4xtable or album.can be used for tag to identify each cell
        filenm2b = filenm2b.SubString(filenm2b.LastIndexOf("/") + 1)
        pnl.GetView(x).GetView(1).Text = filenm2b
        MediaManager.SetMediaFromFile(pnl.GetView(x).GetView(0), xui.DefaultFolder, "myalbum2/"&filenm2b,"image/*", Null) 'l2 is a list of the files
    Next
End If

filenm2b = (List1.Get(x)) <----should be t here instead of x.
 
Upvote 0
Solution

omo

Active Member
Licensed User
Longtime User
I've just went over your code. I see many mistakes.

Don't call ListFiles inside VisibleChanged event. List the files once and store the list.

B4X:
If Success Then
    For x = 0 To 2
        Dim t As Int = data.IndexOfFirstImage + x
        If t >= List1.Size Then
            Exit
        End If
        filenm2b = (List1.Get(x)) 'i should always take note in b4xtable or album.can be used for tag to identify each cell
        filenm2b = filenm2b.SubString(filenm2b.LastIndexOf("/") + 1)
        pnl.GetView(x).GetView(1).Text = filenm2b
        MediaManager.SetMediaFromFile(pnl.GetView(x).GetView(0), xui.DefaultFolder, "myalbum2/"&filenm2b,"image/*", Null) 'l2 is a list of the files
    Next
End If

filenm2b = (List1.Get(x)) <----should be t here instead of x.
Thank you so much Erel, i wouldn't have been able to identify and solve the problem without your help. One question thread solved out of five question threads . I really thank you
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
Hi @omo you marked the wrong message as solved.
Mark Erel 's message as solved. Which will help other members, when they search.
 
Upvote 0
Top