I don't use B4XPages, but the only way I could get it to work was.
1, Make Mainform in Main Public ( ie Dim MainForm .. not Private Mainform ...)
2, Change the FileChooser owner to Main.MainForm ( filename = fc.ShowOpen(Main.mainform) )
Replace fc.ShowOpen(Root) with fc.ShowOpen(MainForm).
Always use code tags (</> on the menu bar) to show your code.
B4X:
Sub Button1_Click
Dim fc As FileChooser
Dim filename As String
fc.Initialize
fc.InitialDirectory = File.DirApp
filename = fc.ShowOpen(MainForm)
Log(filename)
End Sub
I think they did the same as I did , create a new B4XPages app and put the fc code in the button click event. MainForm doesn't exist in that module, so you have to directly reference it 'Main.MainForm'.
Sub Class_Globals
Public FilePath As String' Full directory and filename
Public CurrentfileName As String = "*.txt" ' --- Wanted file type
Public CurrentDirectory As String = File.DirApp ' --- Or default file location between ""
End Sub
and select a file and remember path and filename for later:
B4X:
Dim fc As FileChooser
fc.Initialize
fc.InitialFileName = CurrentfileName
fc.InitialDirectory = CurrentDirectory
FilePath = fc.ShowOpen(B4XPages.GetNativeParent(Me))
If File.Exists(FilePath,"") Then
Log(FilePath)
CurrentDirectory = File.GetFileParent(FilePath)
CurrentfileName = File.GetName(FilePath)
Else
' --- process empty chose
End If
' --- Get the size of the selected file
Log(lstJavaFile.Items.Size)