Martin Larsen Active Member Licensed User Longtime User Feb 12, 2021 #1 I have found that EditText_TextChanged is also called when the text is changed by code. Why is it like that? In what cases can this be useful? The problem is that usually before showing a dialog you will fill out the fields with the existing data. Upon submission of the dialog, you will store the data again. So if you have an EditText_TextChanged sub it will be called already before showing the dialog, namely when initializing the fields in the dialog. This can lead to unexpected side effect until you somehow take precautions. Is there a good way to handle this besides setting a flag before and after you change the text in code?
I have found that EditText_TextChanged is also called when the text is changed by code. Why is it like that? In what cases can this be useful? The problem is that usually before showing a dialog you will fill out the fields with the existing data. Upon submission of the dialog, you will store the data again. So if you have an EditText_TextChanged sub it will be called already before showing the dialog, namely when initializing the fields in the dialog. This can lead to unexpected side effect until you somehow take precautions. Is there a good way to handle this besides setting a flag before and after you change the text in code?
Martin Larsen Active Member Licensed User Longtime User Feb 12, 2021 #2 I found a solution. In my case I was setting a dirty flag to indicate the edit text had changed. The problem was that the dirty flag was set even before showing the dialog as mentioned above. This solved it easily: B4X: Copy Sub edTopic_TextChanged (Old As String, New As String) If pnlSettings.Visible Then edTopicDirty = True End Sub I still wonder why TextChanged is called when modifying the text programmatically, though? Upvote 0
I found a solution. In my case I was setting a dirty flag to indicate the edit text had changed. The problem was that the dirty flag was set even before showing the dialog as mentioned above. This solved it easily: B4X: Copy Sub edTopic_TextChanged (Old As String, New As String) If pnlSettings.Visible Then edTopicDirty = True End Sub I still wonder why TextChanged is called when modifying the text programmatically, though?
E emexes Expert Licensed User Longtime User Feb 12, 2021 #3 What is your TextChanged event handler doing that you don't want done when the text changes? Upvote 0
Martin Larsen Active Member Licensed User Longtime User Feb 12, 2021 #4 In this case, setting the dirty flag. Upvote 0
Martin Larsen Active Member Licensed User Longtime User Feb 12, 2021 #5 I just checked in javascript because I was curious. Here, the onchange event is only fired by user interaction, not if you change the value in code. It's not a big issue now that I know it. I just wonder why it is so. Upvote 0
I just checked in javascript because I was curious. Here, the onchange event is only fired by user interaction, not if you change the value in code. It's not a big issue now that I know it. I just wonder why it is so.
Martin Larsen Active Member Licensed User Longtime User Feb 12, 2021 #6 Okay, apparently this "feature" is baked into Android itself. The Stackoverflow Q&A is very old, but it probably still applies. Upvote 0
Okay, apparently this "feature" is baked into Android itself. The Stackoverflow Q&A is very old, but it probably still applies.
E emexes Expert Licensed User Longtime User Feb 12, 2021 #7 Consistency is usually a good thing. It is simpler to be coding up exceptions where you do want them, than patching over exceptions where you don't want them. ? Upvote 0
Consistency is usually a good thing. It is simpler to be coding up exceptions where you do want them, than patching over exceptions where you don't want them. ?