Retrieve an imagelist from a subfolder to a scrollview

Asmoro

Active Member
Licensed User
Longtime User
Hi all,

I manage to retrieve an imagelist from a folder on the sdcard and
getting displayed on a scrollview.

But I'm having trouble with getting an imagelist from subfolders.:eek:

This is what I have:

B4X:
Sub btAuto_Click    'ListFiles (Dir As String) As List

   f = File.ListFiles(File.DirRootExternal & "/Upload/Auto/")
   StartActivity("results")
End Sub
Sub btMotor_Click
   
   f = File.ListFiles(File.DirRootExternal & "/Upload/Motor/")
   StartActivity("results")
End Sub
Note: it's within a customdialog.

After that, it should appear to a scrollview with this code:

B4X:
Sub LoadImages

   Bitmaps.Initialize
   Dim files As List
   Dim imageFolder As String
   
   imageFolder = File.DirRootExternal & "/Upload/" & "Auto/" & "Motor/"   

   If File.Exists(imageFolder, "") = False Then
      ToastMessageShow("Images not found:" & CRLF & imageFolder, True)
      Return
   End If
   files = File.ListFiles(imageFolder) 
   For i = 0 To files.Size - 1
      DoEvents 
      Dim f As String
      f = files.Get(i)
      If f.ToLowerCase.EndsWith(".jpg") Then
         Dim b As Bitmap
         b.InitializeSample(imageFolder, f, 300dip, 300dip) 
         Bitmaps.Add(b)
         If Bitmaps.Size > 50 Then Exit 
      End If
   Next
   ToastMessageShow(Bitmaps.Size & "  found", False)
End Sub

Too bad, it didn't work.
Anyone having a solution for this?
 

Asmoro

Active Member
Licensed User
Longtime User
Hi Klaus,

I'm using your custom dialog and scrollview example.
Both are working well, so I think that's not the problem.

Offcourse I was checking your scrollview summary but
can't find the relation with retrieving from a subfolder to a scrollview.
Could be that I missed that part though.

I believe that has something to do with the relation between
the path or syntax of a subfolder and scrollview.

And I've read somewhere at the forum someone saying that file.listfile
is not working properly, combining with subfolders.

I hope that is not the issue here.

Here's some code of the scrollview:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   
   If FirstTime Then                                  
      ProgressDialogShow("Loading images")
      LoadImages
      ProgressDialogHide
   End If
   
   Activity.LoadLayout("results")                            
   ScrollView1.Panel.Height = 300dip * Bitmaps.Size          
   For i = 0 To Bitmaps.Size - 1
      Dim iv As ImageView                            
      iv.Initialize("iv")                              
      Dim bd As BitmapDrawable
      bd.Initialize(Bitmaps.Get(i))
      iv.Background = bd                               
      ScrollView1.Panel.AddView(iv, 5dip, 5dip + i * 300dip, ScrollView1.Width - 10dip, 290dip)  
   Next
   
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but without having the whole project or at least a smaller project showing the problem it's impossible to find what happes.
With just a few code snippets there remain too many open questions on what type are several variables, where and how they are defined, in what Activity the routines are ?
What type is the variable f, used differently in different routines.
You have different path names:
f = File.ListFiles(File.DirRootExternal & "/Upload/Auto/")
f = File.ListFiles(File.DirRootExternal & "/Upload/Motor/")
and somewhere else:
imageFolder = File.DirRootExternal & "/Upload/" & "Auto/" & "Motor/"

Best regards.
 
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Klaus,

I understand, so I'm gonna make a small project regarding the problem.

But before I do that, if the path I use didn''t work, what is the standard/main syntax or code path with list.listfile if:
1. Folder on sdcard = Upload
2. Subfolders of Upload = "Auto" and "Motor"
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
This case
imageFolder = File.DirRootExternal & "/Upload/" & "Auto/" & "Motor/"
is equal to :
imageFolder = File.DirRootExternal & "/Upload/Auto/Motor/"
I don't think that you have this subfolder.

I have never used File.ListFile but from the help file you can give only one path.
Have you tried with File.ListFile(File.DirRootExternal & "/Upload/") ?
I don't know if it looks also for subfolders.

Best regards.
 
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Yes, I made subfolders manually, it's in there alright.
I tried all kinds of ways to get the path and tried your solution.
With 'File.DirRootExternal & "/Upload/" it worked and no looking for subfolders same time.

So the basic problem is the right path to the subfolders.

note: working on a testproject right now
 
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Hi Klaus,

imageFolder = File.DirRootExternal & "/Upload/Auto/Motor/"
I don't think that you have this subfolder.

I mean subfolders 'Auto' and 'Motor' in folder 'Upload'.

As promised I made a little testproject regarding the problem.
Offcourse everyone can contibute a nice solution by testing the project.

note: create on your sdcard a folder named Upload and inside
the Upload folder, 2 subfolders Auto and Motor.

Put some pictures in the (sub)folders as well to get this project working.

Hope a nice solution in the end.;)
 
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Here you are.

It would have been easier and faster if you had added the images for the test program and also some images for the subfolders.

Best regards.

Thanks Klaus, you're right, I will do that next time for other tests.

Just curious, are there any kind of limitations custom dialogs have
that you know of?
Things like FTP connection, some view functions etc. (not much doc. info)
 
Upvote 0
Top