Android Question EditText ALWAYS empty no matter what i do

I m just trying to make a register layer and still impossible due to EditText.Text always considered as empty, even when the user writes in the EditText :/ . I didn t find any thread about that...
I m a beginner on B4A so the issue can be a stupid mistake


layer's code:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private txtEmail As EditText
    Private txtPassword As EditText
    Private txtAddress As EditText
    Private btnRegister As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("layRegister")
   
    'Initialize elements
    txtEmail.Initialize("Email")
    txtPassword.Initialize("Password")
    txtAddress.Initialize("Address")
   
    btnRegister.Initialize("Register")

End Sub

Sub Activity_Resume
   
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub btnRegister_Click
   
    If txtEmail.Text = "" Then
        MsgboxAsync("Email cannot be empty","")
        Return
    End If
   
    'Limit the data you want from the file (SQLite) by using a cursor
    Dim rs As ResultSet
    rs = Starter.sql.ExecQuery("SELECT user_name FROM User WHERE user_name='"& txtEmail.Text &"'")
   
    MsgboxAsync("", txtEmail.Text)
   
    If rs.RowCount > 0 Then
        MsgboxAsync("Email already used", "Failed")
    End If
    If rs.RowCount == 0 Then
        Starter.sql.ExecNonQuery("INSERT INTO User (user_name, user_password, user_address) VALUES ('"&  txtEmail.Text  &"' , '"& txtPassword.Text &"', '"& txtAddress.Text &"')")
        MsgboxAsync("Record saved", "Successed")
    End If
   
    rs.Position = 0
    rs.Close
   
End Sub

Private Sub txtEmail_TextChanged (Old As String, New As String)
    txtEmail.Text = New
    Log("hey")
End Sub
 

Attachments

  • 1628187947620.png
    1628187947620.png
    77 KB · Views: 157
I maybe found a way to update it but i m sure there is a much better way because of course Old is the string minus the last letter...

B4X:
Private Sub txtEmail_TextChanged (Old As String, New As String)
    
    txtEmail.Text = Old
    Log(txtEmail.Text)
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
'Initialize elements txtEmail.Initialize("Email") txtPassword.Initialize("Password") txtAddress.Initialize("Address")
This is the problem. You should NOT initialize Objects which are part of a Layout.
 
Upvote 0
This is the problem. You should NOT initialize Objects which are part of a Layout.
Ah thanks ! It works now. I m just wondering why trying to read "Old" in text_changed event makes the app crash, but i absolutely don t need to so it s not that important (just trying to understand).
 
Upvote 0
Top