Android Question .

klaus

Expert
Licensed User
Longtime User
You could also have done it that way without intermediate variables and a List:
B4X:
Sub Process_Globals
    Dim DirName As String        : DirName = File.DirRootExternal & "/SavedGame"
    Dim FileName As String    : FileName = "PokerTracker_Stats.txt"
End Sub

Sub Globals
    Dim EditText1, EditText2, EditText3, EditText4 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
End Sub

Sub Activity_Resume
    
    If File.Exists(DirName, FileName) Then
        LoadINI
    Else
        EditText1.Text = "Test1"
        EditText2.Text = "Test2"
        EditText3.Text = "Test3"
        EditText4.Text = "Test4"
    End If
End Sub

Sub Activity_Pause(UserClosed As Boolean)
    If Not(File.Exists(DirName, "*")) Then
        File.MakeDir(File.DirRootExternal, "SavedGame")
    End If
    SaveINI
End Sub

Sub LoadINI
    Dim rw As TextReader

    rw.Initialize(File.OpenInput(DirName, FileName))
    EditText1.Text = rw.ReadLine
    EditText2.Text = rw.ReadLine
    EditText3.Text = rw.ReadLine
    EditText4.Text = rw.ReadLine
    rw.Close
End Sub

Sub SaveINI
    Dim tw As TextWriter
    
    tw.Initialize(File.OpenOutput(DirName, FileName, False))
    tw.WriteLine(EditText1.Text)    
    tw.WriteLine(EditText2.Text)    
    tw.WriteLine(EditText3.Text)    
    tw.WriteLine(EditText4.Text)    
    tw.Close
End Sub
These functions are explained in the Beginner's Guide chapters 13.10.4 and 13.14.5

Best regards.
 
Upvote 0

coslad

Well-Known Member
Licensed User
Longtime User
hi klaus,
i have a question , if the edittext have a CF + LF character , it will save in a single line ? otherwise your code will not work.
thanks
 
Upvote 0
Top