Attached is a little program shows how to read a directory content, show the filenames in a listview, and showing an example of the selected image file in imageview.
Duplicated from the original post in the spanish forum.
Here is the code:
enjoy
Duplicated from the original post in the spanish forum.
Here is the code:
B4X:
Sub Process_Globals
End Sub
Sub Globals
Dim ListView1 As ListView
Dim ImageView1 As ImageView
Dim Label1 As Label
Dim path1,file1 As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim GD As GradientDrawable
GD.Initialize("TR_BL", Array As Int(Colors.Blue, Colors.LightGray))
Activity.Background = GD
ListView1.Initialize("ListView1")
ListView1.ScrollingBackgroundColor = Colors.Transparent
ImageView1.Initialize("test")
ImageView1.Color = Colors.ARGB(25,0,0,0)
Label1.Initialize("Label1")
Label1.Color = Colors.argb(90,0,0,0)
Label1.TextColor = Colors.Yellow
Label1.TextSize = 9
ListView1.SingleLineLayout.ItemHeight = 50dip
ListView1.SingleLineLayout.Label.TextSize = 20
ListView1.SingleLineLayout.Label.TextColor = Colors.White
ListView1.SingleLineLayout.Label.Gravity = Gravity.LEFT
ListView1.FastScrollEnabled = True
root=File.DirRootExternal
path1 = root & "/DCIM/Camera"
ListFolderContent(path1)
Activity.AddView(ListView1, 0, 0, 100%x, 50%y)
Activity.AddView(Label1, 0, 50%y, 100%x, 30dip)
Activity.AddView(ImageView1, 0, (50%y + 30dip), 100%x, 50%y)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ListFolderContent(folder As String) As String
Dim fileList As List
Dim n As Int
fileList = File.ListFiles(path1)
fileList.Sort(True)
For n = 0 To fileList.Size-1
file1 = fileList.Get(n)
ListView1.AddSingleLine(file1)
Next
End Sub
Sub ListView1_ItemClick (Position As Int, Value As Object)
Activity.Title = "Selected: ("& Position &") <" & Value &" >"
Try
ImageView1.Bitmap = LoadBitmapSample(path1,Value, ImageView1.Width, ImageView1.Height)
Label1.Text = "Ok."
Catch
Label1.Text = "error " & LastException
End Try
End Sub
enjoy