Jump to content
Registration disabled at the moment Read more... ×
John van de Waeter

TEdit and OnTyping event

Recommended Posts

Hi All,

Just noticed. The OnTyping event is fired differently depending on the Android version.

I have a TEdit that is used for incremental text searching.

The user types, I use the OnTyping event to read the text from the TEdit and use this text to scan a table for keywords.

Works okay on Windows, Mac, iOS and Android 12 (Samsung Galaxy Tablet).

 

On all targets, the Ontyping event is fired once for every typed character.

On my Galaxy S21, Android 15, however, the event is fired again and again for the length of the typed text. 

So if I type 'tha' 

I should have 3 events. Edit.text = 't', edit.text='th' edit.text='tha'.

 

On my Galaxy S21, Android 15, I get 6 events:

type the t:   1 event fired: edit.text ='t'

type the h:   2 events fired: edit.text='t', immeditaely followed by edit.text='th'

type the a:   3 events fired: edit.text='t', edit.text='th', edit.text='tha'.

 

So as many events as the length of the typed text.  This continues until the user types a space.

In that case only one event is fired and inside this event, edit.text equals the contents of the Tedit. As expected.

 

My dev: Delphi 12.3, Android 25.2.5 both 32 and 64 bit

 

Unfortunately I don't have more Android devices to test...

 

Is this a problem in Android 15?

 

tia,

John

 

 

 

 

Share this post


Link to post

In the past, when I had issues with my Android apps, it happned nearly only on some Samsung devices; so I thought already that it is the Samsung keyboard...

 

Samsung can everything, besides software 😉

 

Share this post


Link to post

And the most strange issue I had with Samsung devices, was that when you copied a bulk of pictures to a windows device via USB, some pictures had the content of another picture. And we had links to such pictures in our database and the customer told us we are doing something wrong, showing the wrong pic. Difficult to find the issue...

Share this post


Link to post

At least I could tell them that the issue is related to Samsung.

 

For the picture issue there were only a workaround (when you had still the pictures on android device): Copying the issued pic to a new empty folder with android file app and then copy this to windows.

 

I by myself avoid Samsung galaxys and recommend other phones to peaple who ask me.

 

Share this post


Link to post

Hmm... It's one of the most used android phones... anyway, I noticed on a friends' Galaxy/Android 13 the TEdit with the OnTyping event has issues as well...

Time to figure out just another workaround...

Share this post


Link to post

You could save the content of the edit in a variable and then first check if content has changed.

 

And you could try if it makes a difference when you set the edit to "platform" or not.

Share this post


Link to post

The problem is that the events OnTyping , OnValidating , OnChangeTracking, OnKeyUp, OnKeydown ALL are fired as many times as there are characters in the EditBox.

 

That is, on my Galaxy 21, Android 15.

 

I could work around it if I would know how many characters are in the EditBox, like length(editbox.text), but inside the eventhandler, that number gives me 0,1,2,3,4,.. NOT the actual length of the contents of the editbox.

 

Is there a way to access the underlying editbox, in which on screen I can clearly see e.g. 6 characters, that gives me a "6"? 


In that case I could count the number of events and know which one is the last one and act upon it.

 

 

Share this post


Link to post
4 hours ago, John van de Waeter said:

The problem is that the events OnTyping , OnValidating , OnChangeTracking, OnKeyUp, OnKeydown ALL are fired as many times as there are characters in the EditBox.

 

That is, on my Galaxy 21, Android 15.

 

I could work around it if I would know how many characters are in the EditBox, like length(editbox.text), but inside the eventhandler, that number gives me 0,1,2,3,4,.. NOT the actual length of the contents of the editbox.

 

Is there a way to access the underlying editbox, in which on screen I can clearly see e.g. 6 characters, that gives me a "6"? 


In that case I could count the number of events and know which one is the last one and act upon it.

 

 

That sounds like the OS/keyboard is retyping content into the edit control. The edit does go back to being empty and then having 1,2,3 etc characters in it just within a short period of time.

 

One thought: keep track of the last partial search string and start/reset a short timer in the OnXXX events. When the timer event triggers check if the edit content is not equal to what was last searched for and update the search as appropriate. This gives time for the OS/keyboard to be done changing the edit contents before you use it's contents in your search. 

Share this post


Link to post

 

2 hours ago, Brian Evans said:

That sounds like the OS/keyboard is retyping content into the edit control. The edit does go back to being empty and then having 1,2,3 etc characters in it just within a short period of time. 

Yes, it looks somewhat in that direction, given the fact that another keyboard (GBoard) does not have the problem.

2 hours ago, Brian Evans said:

One thought: keep track of the last partial search string and start/reset a short timer in the OnXXX events. When the timer event triggers check if the edit content is not equal to what was last searched for and update the search as appropriate. This gives time for the OS/keyboard to be done changing the edit contents before you use it's contents in your search. 

Yes, I made something similar. Not using the events ,nor a timer, but polling the text from the editbox in the app's OnIdle event. Kinda dirty, but it works :)

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×