Android File Dialog Tutorial using Basic4Android

This is my continuation in our Dialog example and next to be discussed is the File Dialog. First, we have to create our Layout name and named it as "Main" and have one button named Button1. You need to initialized the following variables in the Sub Globals below:
  1. Sub Globals
  2. 'These global variables will be redeclared each time the activity is created.
  3. 'These variables can only be accessed from this module.
  4.  
  5. Dim Button1 As Button
  6. Dim bmp As Bitmap
  7. End Sub
Take note that bmp here is used as our variable to create an icon for our file dialog. Here is our complete code for this tutorial:
  1. Sub Process_Globals
  2. 'These global variables will be declared once when the application starts.
  3. 'These variables can be accessed from all modules.
  4.  
  5. End Sub
  6. Sub Activity_Create(FirstTime As Boolean)
  7. 'Do not forget to load the layout file created with the visual designer. For example:
  8. 'Activity.LoadLayout("Layout1")
  9. Activity.LoadLayout("Main")
  10. bmp.InitializeSample(File.DirAssets, "bermoy.jpg",48,48)
  11. Activity.Title = "File Dialog - Lyndon Bermoy"
  12.  
  13. End Sub
  14.  
  15. Sub Activity_Resume
  16.  
  17. End Sub
  18.  
  19. Sub Activity_Pause (UserClosedAs Boolean)
  20.  
  21. End Sub
  22.  
  23. Sub Button1_Click
  24. Dim fd As FileDialog
  25. Dim ret As Object
  26. fd.FastScroll = True
  27. fd.KeyboardPopUp = False
  28. 'fd.ShowOnlyFolders = True
  29. fd.FilePath = File.DirRootExternal ' also sets ChosenName to an emtpy string
  30. 'fd.ShowOnlyFolders = true
  31. 'fd.FileFilter = ".txt" ' for example or ".jpg,.png" for multiple file types
  32. ret = fd.Show("B4A File Dialog", "Yes", "No", "Maybe", bmp)
  33. ToastMessageShow(ret & " : Path : " &fd.FilePath& CRLF & "File : " &fd.ChosenName, False)
  34. End Sub
Note: fd - used as our variable for FileDialog ret - used as our variable for Object. fd.FastScroll - a boolean syntax if you want to have the speed of the scrollbar to make fast. fd.KeyboardPopUp - syntax for pop-upping the keyboard. fd.FileFilter - syntax for filtering the type of file to be searched. For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment