Android Question EditText EnterPressed not recognized

David_B

New Member
Hi Guys,

I am pretty new here, trying to do very simple app.

Having 2 EditText inputs but even the code is the very same, the 1st is catching enter just fine but the 2nd is not.

Anyone to tell me the sweet secret what's wrong?

Thanks for answer!

D./

Here the code:

B4X:
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.
    Dim EditText1 As EditText
    Dim EditText2 As EditText
    Dim label1 As Label
    Dim label2 As Label
    Dim scan1 As String
    Dim scan2 As String
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")

    label1.Initialize("Label1")
    Activity.AddView(label1, 10%x, 5%y, 70%x, 6%y)
    label1.Text = "1.) scan1"
    label1.TextColor = Colors.White
    label1.TextSize = 20
    
    EditText1.Initialize("EditText1")
    Activity.AddView(EditText1, 10%x, 10%y, 70%x, 6%y)
    EditText1.Text = ""
    EditText1.Color = Colors.White
    EditText1.TextColor = Colors.black
    EditText1.TextSize = 20
    EditText1.SingleLine = True
    
    label2.Initialize("Label2")
    Activity.AddView(label2, 10%x, 25%y, 70%x, 6%y)
    label2.Text = "2.) scan2"
    label2.TextColor = Colors.White
    label2.TextSize = 20
    
    EditText2.Initialize("EditText2")
    Activity.AddView(EditText2, 10%x, 30%y, 70%x, 6%y)
    EditText2.Text = ""
    EditText2.Color = Colors.White
    EditText2.TextColor = Colors.Black
    EditText2.TextSize = 20
    EditText1.SingleLine = True
    
End Sub

Sub EditText1_TextChanged(Old As String,New As String)
    Dim ET1 As EditText = Sender
    ET1.Color = Colors.Blue
    scan1 = ET1.text
End Sub

Sub EditText2_TextChanged(Old As String,New As String)
    Dim ET2 As EditText = Sender
    ET2.Color = Colors.Blue
    scan2 = ET2.text
End Sub

Sub EditText1_EnterPressed
    Dim ET3 As EditText = Sender
    ET3.Color = Colors.Red
        
End Sub

Sub EditText2_EnterPressed
    Dim ET4 As EditText = Sender
    ET4.Color = Colors.Red

End Sub
 

stevel05

Expert
Licensed User
Longtime User
Your edittext2 code block is
B4X:
    EditText2.Initialize("EditText2")
    Activity.AddView(EditText2, 10%x, 30%y, 70%x, 6%y)
    EditText2.Text = ""
    EditText2.Color = Colors.White
    EditText2.TextColor = Colors.Black
    EditText2.TextSize = 20
    EditText1.SingleLine = True

Which is setting EditText1.SingleLine = True instead of EditText2.SingleLine = True
 
Upvote 0
Top