Android Question TextChanged event

Chianca

Member
Licensed User
Longtime User
Hello, i'm having some problems to fire the TextChanged event of an EditText, cause i'm creating it by code, like this example above:

ScrollView_Customer.Panel.AddView(CreateTextBox("0","EdtName","Name"),0,TopDistance,EditTextWidth,EditTextHeight)

The CreateTextBox return an EditText element and before i create it, i cant use TextChanged event of this EditText. How can i solve this problem?


Thanks to all!
 

stevel05

Expert
Licensed User
Longtime User
Can you show us the code of the CreateTextBox and the signature for the CallBack sub "_TextChanged(Old As String, New As String)"
 
Upvote 0

Chianca

Member
Licensed User
Longtime User
Can you show us the code of the CreateTextBox and the signature for the CallBack sub "_TextChanged(Old As String, New As String)"

Sure, here is the code:

1st: Add the EditText:
B4X:
ScrollView_Customer.Panel.AddView(CreateTextBox("0","EdtName","Name"),0,TopDistance,EditTextWidth,EditTextHeight)

2nd: CreateTextBox SUB:
B4X:
'Sub CreateTextBox
Sub CreateTextBox(DataType As String,TagId As String, TxtHint As String) As EditText
  Dim edt As EditText
    edt.Initialize("EditText")
  edt.SingleLine = True
  edt.Tag = TagId
  edt.Hint = TxtHint
  edt.Color = Colors.RGB(240,240,240)
  edt.TextColor = Colors.Black
  If DataType = "0" Then
    edt.InputType = edt.INPUT_TYPE_TEXT
    Else If DataType = "1" Then
    edt.InputType = edt.INPUT_TYPE_NUMBERS
    Else If DataType = "2" Then
    edt.InputType = edt.INPUT_TYPE_DECIMAL_NUMBERS
    Else If DataType = "3" Then
    edt.InputType = edt.INPUT_TYPE_PHONE
  End If
    Return edt
End Sub

3rd: TextChanged
B4X:
'TextChanged Event
Sub EdtName_TextChanged(Old As String,New As String)
  EdtName.color = Colors.White
End Sub
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You are initializing the EditText EventName as "EditText". The TextChanged event sub signature should be:

B4X:
Sub EditText_TextChanged(Old As String,New As String)
     Dim ET AS EditText = sender
     ET.Color = Colors.White
End Sub

to get the EditText that was changed you need to use the Sender keyword as in my example.
 
Upvote 0

Chianca

Member
Licensed User
Longtime User
You are initializing the EditText EventName as "EditText". The TextChanged event sub signature should be:

B4X:
Sub EditText_TextChanged(Old As String,New As String)
     Dim ET AS EditText = sender
     ET.Color = Colors.White
End Sub

to get the EditText that was changed you need to use the Sender keyword as in my example.

Hey Man, thank you! Your tip has solved my problem, it works perfectly!
 
Upvote 0
Top