Android Question Unable to get New text from editText_TextChanged event

rossco_pb

Member
Licensed User
Longtime User
Can anyone offer any advice as to why I cannot get the editText_TextChanged event to show any new text that is entered into the field. The Old text changes but not the new. I am basically wanting to count how many characters are in the field by keeping a count but cannot make the count increment, only decrement as is shown by code and log snippets as "New" does not update.

Also tried the CharCounter (Ver 1.00) Library and that always returns a count of zero??

Am using version 3.82 of B4a

Log as follows for below code. Basically just logging each time I hit a character (3 of them) and using the backspace to delete.

0 and then new 0 ' a showing in edtText field at this point
1 a and then new 0 ' ab showing
2 ab and then new 0 ' abc showing

3 abc and then new 0 ' ab showing after backspace
2 ab and then new 0 ' a showing
1 a and then new 0 ' nothing showing

Given I am a newbie probably something simple I am doing wrong ;-)


B4X:
Sub edtText_TextChanged (Old As String, New As String)
   
    ' Ascending.Update(Old, New)
   
    Log(sf.Len(Old) & " " & Old & " and then new " & sf.Len(New) & " " & New)
   
End Sub
 

klaus

Expert
Licensed User
Longtime User
Works OK on my computer !?
You don't need StringFunctions the get the lenght of a string.
In B4A sf.Len(Old) -> Old.Lenght
I tested it with:
B4X:
Sub edtTest_TextChanged (Old As String, New As String)
    Log(Old.Length & " " & Old & " : " & New.Length & " " & New)
    Log(sf.Len(Old) & " " & Old & " and then new " & sf.Len(New) & " " & New)
End Sub
And the result:
0 : 1 a
0 and then new 1 a
1 a : 2 ab
1 a and then new 2 ab
2 ab : 3 abc
2 ab and then new 3 abc
3 abc : 2 ab
3 abc and then new 2 ab
2 ab : 1 a
2 ab and then new 1 a
1 a : 0
1 a and then new 0
0 : 1 h
0 and then new 1 h
** Activity (main) Resume **
 
Upvote 0

rossco_pb

Member
Licensed User
Longtime User
Works OK on my computer !?
You don't need StringFunctions the get the lenght of a string.
In B4A sf.Len(Old) -> Old.Lenght
I tested it with:
B4X:
Sub edtTest_TextChanged (Old As String, New As String)
    Log(Old.Length & " " & Old & " : " & New.Length & " " & New)
    Log(sf.Len(Old) & " " & Old & " and then new " & sf.Len(New) & " " & New)
End Sub
And the result:


Many thanks for your prompt reply Klaus but same result for me using the Old.Length/New.Length method (old habits die hard). Will do a fresh install of B4a to see if problem persists and let you know. Very confusing...
 
Upvote 0

rossco_pb

Member
Licensed User
Longtime User
Works OK on my computer !?
You don't need StringFunctions the get the lenght of a string.
In B4A sf.Len(Old) -> Old.Lenght
I tested it with:
B4X:
Sub edtTest_TextChanged (Old As String, New As String)
    Log(Old.Length & " " & Old & " : " & New.Length & " " & New)
    Log(sf.Len(Old) & " " & Old & " and then new " & sf.Len(New) & " " & New)
End Sub
And the result:


Well have not determined the exact cause as yet but with a fresh source file and just an edittext type and the sub to log old and new it works fine as per what you reported. I then started adding my other code/libraries etc to it and at some point it broke again. What is interesting is if I reverse the last changes and even if I go back to the original basic piece of code (extra libraries etc removed) it does not resolve the issue - some state or data stored in the meta file perhaps... Will keep messing with it until I narrow it down.
 
Upvote 0

rossco_pb

Member
Licensed User
Longtime User
Works OK on my computer !?
You don't need StringFunctions the get the lenght of a string.
In B4A sf.Len(Old) -> Old.Lenght
I tested it with:
B4X:
Sub edtTest_TextChanged (Old As String, New As String)
    Log(Old.Length & " " & Old & " : " & New.Length & " " & New)
    Log(sf.Len(Old) & " " & Old & " and then new " & sf.Len(New) & " " & New)
End Sub
And the result:

It is all very strange but appears calling a sub called "New" is what triggers the condition per the sample following. If I change the name of the routine to anything else the problem goes away. If called New it is invoked every time a key hit. Do you get the same effect? I can solve my issue by not using "New" but would be interested as to why it happens...


B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#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 EditText1 As EditText

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("Main")
   
    Msgbox("running","")
    New

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub New

    Msgbox("In new","")

End Sub
Sub EditText1_TextChanged (Old As String, New As String)

    Log(Old.Length & " " & Old & " : " & New.Length & " " & New)

End Sub
 
Upvote 0

rossco_pb

Member
Licensed User
Longtime User
Yes, I get the same effect.
You should not use same names for variables and subroutines.

Thanks for the confirmation - did not twig to that being the issue as thought of "New" the variable as being local to the sub. Live and learn ;-)
 
Upvote 0
Top