Android Question Problem with List View

Izmirov.Yaminovich

Member
Licensed User
Longtime User
B4X:
Sub Button4_Click
    Activity.LoadLayout("2nd")
   
    ListView1.Initialize("ListView1")

    Activity.AddView(ListView1, 0, 0, 100%x, 70%y)
   
    ListView1 = File.ListFiles(File.DirInternal)
   
    Panel1.Visible = False
    Panel3.Visible = True
End Sub

Above are my list view coding. What it was supposed to do is to show me other page that consist of the list view of the files that I have had in my saved files when I click the button. However, when I clicked it, there's an error on it and it just opt out. I thought putting in the ListView1 = File.ListFiles(File.DirInternal) code was supposed to lead me to the saved files. Anybody know what have I done wrong and explain it to me please? I'll attach the full in this post.
 

Attachments

  • test.zip
    11.1 KB · Views: 100

mangojack

Expert
Licensed User
Longtime User
you are confusing ListView with List ...
use List.ListFiles(path) first , then loop thru the list adding items to the ListView.

search for ListFiles .. you will see many examples.

Have you looked at the beginners guide yet ? Beginners Guide ...
and Users Guide ....
 
Upvote 0

Izmirov.Yaminovich

Member
Licensed User
Longtime User
B4X:
Sub ListFiles(dir As String)
Dim list_files As List
Dim lista_folders As List
lista_folders.Initialize
    list_files=File.ListFiles(dir)
    For i= 0 To list_files.Size -1
        If File.IsDirectory(dir, list_files.Get(i))=false Then
            lista_folders.Add(list_files.Get(i))
        End If
    Next
Return lista_folders
End Sub

I found this in one of the post.
If File.IsDirectory(dir, list_files.Get(i))=false Then
lista_folders.Add(list_files.Get(i))
End If
What does that mean? list_files.Get(i) , where do that come from?

And I guess by writing so I'll not need to draw any layout for it?
 
Last edited:
Upvote 0

Izmirov.Yaminovich

Member
Licensed User
Longtime User
Okay, here's what I did. Still nothing though. error with the script.
B4X:
Sub Button4_Click
    Activity.LoadLayout("2nd")
   
    ListView1.Initialize
    list_files=File.ListFiles(File.DirInternal)
    For i= 0 To list_files.Size -1
        If File.IsDirectory(File.DirInternal, list_files.Get(i))=False Then
            ListView1.Add(list_files.Get(i))
        End If
    Next
   
    Panel1.Visible = False
    Panel3.Visible = True
End Sub
 
Upvote 0

Izmirov.Yaminovich

Member
Licensed User
Longtime User
B4X:
Sub ListFiles(dir As String)
    lista_folders.Initialize
    list_files=File.ListFiles(File.DirInternal)
    For i= 0 To list_files.Size -1
        If File.IsDirectory(File.DirInternal, list_files.Get(i))=False Then
            lista_folders.Add(list_files.Get(i))
        End If
    Next
Return lista_folders
End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
    Activity.Title = Value
End Sub

Sub Button4_Click
    Activity.LoadLayout("2nd")
   
    ListView1.Initialize("ListView1")
       ListView1 = lista_folders
    Activity.AddView(ListView1, 0, 0, 100%x, 70%y)
   
    Panel1.Visible = False
    Panel3.Visible = True
End Sub

I now have the files, how to I put it in the list view? I tried ListView1 = lista_folders. It's not working.
 
Upvote 0
Top