B4J Question Try to make a safe dialoig

appie21

Active Member
Licensed User
Longtime User
Hi

I try to save a local txt file
But I get this error

B4X:
B4J line: 135
ret = fd.Show(\
javac 1.8.0_121
src\b4j\example\main.java:139: error: package android.graphics does not exist
_ret = _fd.Show((java.lang.CharSequence)("Please Enter File Name"),"Save","Cancel","",ba,(android.graphics.Bitmap)(anywheresoftware.b4a.keywords.Common.Null));
                                                                                                          ^
1 error


my code is


B4X:
Sub BtnStop_Click
    Dim fd As FileDialog
    Dim ret As Int
    Dim sets As Map
    fd.FastScroll = True
    fd.FilePath = File.DirApp ' also sets ChosenName to an emtpy string
    fd.ChosenName = "txt"
    ret = fd.Show("Please Enter File Name", "Save", "Cancel", "",Null)
    If ret = -1 Then
        sets.Clear
        sets.Put("TextArea1", TextArea1.Text)
        
        File.WriteMap(fd.FilePath, fd.ChosenName & ".txt", sets)
    End If
End Sub

What do I wrong
I have add Dialog 4.01 to the libary
 

stevel05

Expert
Licensed User
Longtime User
FileDialog is an android library. In B4j you can use FileChooser, it is an internal library.
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
oops ;)
But now ho to save my file File.WriteString(File.DirApp, "1.txt", TextArea1.Text)
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
Hi thanks

I want that the user can save the file where he want

Where do i set the action for (when pressed the save button?)


I have now
B4X:
    DialogSave.Initialize
    DialogSave.setExtensionFilter("tekst", Array As String("*.txt"))
    DialogSave.ShowSave(MainForm)

The data what i will save is File.DirApp, "1.txt" or found in TextArea1.Text

I have found this out (didn't work because file is damaged after reopen

B4X:
DialogSave.Initialize
    DialogSave.setExtensionFilter("tekst", Array As String("*.txt"))
    DialogSave.ShowSave(MainForm)
    Log (DialogSave.InitialDirectory)
    File.WriteString(DialogSave.InitialDirectory, DialogSave.InitialFileName, TextArea1.Text)
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The showsave method returns the selected filepath

Try this:

B4X:
DIm FP As String = DialogSave.ShowSave(MainForm)
If FP = "" Then Return
File.WriteString(File.GetFileParent(FP), File.GetName(FP), TextArea1.Text)
 
Upvote 0
Top