When I write some values to the textfield, it holds the value at the foreground and background. But if app is killed and run again, the value is lost and textfield comes back empty. How can I provide textfield holds the value entered although app is killed?
Ohh, I have forgotten this case.
Check if the file "user" exists, before you try to read the information:
B4X:
Private Sub Application_Start (Nav As NavigationController)
If File.Exists(File.DirDocuments,"user") Then
TextField1.Text = File.ReadMap(File.DirDocuments,"user").Get("username")
Else
TextField1.Text = "default value"
End If
End Sub
It is not related to this topic but may I ask another question about text field? If the entered value into the TextField includes characters, it will not be accepted. I wrote the codes below. I used AnyChr as Char, but there is a log. It says "Variable 'AnyChar' is never assigned any value. (warning#10) How can I solve this?
B4X:
Dim AnyChr As Char
If TextFieldimei.Text.Contains(AnyChr) Or TextFieldimei.Text.Length <> 15 Then
Msgbox(warning2, warningtitle1)
TextFieldimei.Text = ""
Else
File.WriteMap(File.DirDocuments,"user",CreateMap("userimei":TextFieldimei.Text))
End If
End Sub
If Not(IsNumber(TextFieldimei.Text)) Or TextFieldimei.Text.Length <> 15 Then
Msgbox(warning2, warningtitle1)
TextFieldimei.Text = ""
Else
File.WriteMap(File.DirDocuments,"user",CreateMap("userimei":TextFieldimei.Text))
End If