Spanish Ayuda listando ficheros de un directorio

psdos

Active Member
Licensed User
Longtime User
Buenas chicos, pues mi primera pregunta tras la presentacion es para ver si me echais un cable con el codigo para lo que estoy haciendo.

Me gustaria mostrar en un ListView los ficheros que hay en un directorio y que al seleccionar uno de la lista se carge en un imagebox.

A ver si me ayudais a iniciarlo, muchas gracias.
 

joseluis

Active Member
Licensed User
Longtime User
Te he escrito un ejemplo. Me he basado en el código de este hilo para crear un ejemplo sencillo que enseña lo que entiendo que quieres conseguir.

Hace una lista de las imágenes guardadas por la cámara y de la que seleccionas, muestra un trozo en un ImageView.

Adjunto el programa, y aquí pego el código:

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

Para más información aquí tienes un tutorial de ListView. Y el imagebox de VB aquí se llama Imageview.

que lo disfrutes! :)

EDIT: Copiado al foro inglés.
 

Attachments

  • ListviewDircontentImagebox.zip
    6.1 KB · Views: 489
Last edited:

psdos

Active Member
Licensed User
Longtime User
Muchisimas gracias joseluis, si es lo que quiero, tengo hecha una parte pero este codigo me hara poder acabar mi aplicacion.

Gracias una vez mas. Un saludo.
 
Top