Android Question Multiple EditText_TextChanged

danijel

Active Member
Licensed User
Longtime User
Hi guys,

I have 60 EditText Views.

On Each EditText_TextChanged
MyCalculation()
method is triggered.
(very difficult and time consuming)

My question is: Is there an elegant way to avoid 60 times calling MyCalculation()
if all 60 EditText views are changed at once
(Just one call is needed).


Thank you
 

danijel

Active Member
Licensed User
Longtime User
Thank you Klaus for your interest.
MyCalculation() is doing Iterative Math methods with EditText.Text as input parameters...
and in this case it doesn't even matter...
Only need one call instead of 60 calls when all 60 EditText are changed.
 
Upvote 0

emexes

Expert
Licensed User
Is the problem that MyCalculation takes some time? Not that it makes any difference here but: perhaps a side-project is to speed that up, like... maybe it is doing a lot of redundant string-to-number conversions: they can chew up way more time than the actual math itself.

Returning to the actual question:

You could have a private global CalculationEnableFlag that you temporarily set to False when the bulk calls occurs (loading up EditTexts with initial values?) and then set back to True and do a single call immediately after.

Or you could do something similar within the calculation Sub to throttle it, ie if if it is less than a second since the last time it was called, then instead set a timer to do the calc in the near future.

Or if that feels too fragile or complex, another way is to have a private global RecalculateFlag that is set whenever one of the source variables changes, and checked regularly by a timer tick that, if the flag is set, clears the flag FIRST and then performs the calculation.
 
Last edited:
Upvote 0

danijel

Active Member
Licensed User
Longtime User
Thx Emexes for your time!

Actually I solved it in very similar way:

B4X:
'Use when manual input
Sub ET_TextChanged (Old As String, New As String)
   If ET.Enabled=True Then MyCalculation()
End Sub

B4X:
'Use when all EditText Changes
Sub ChangeAll
   For i=0 to ET.lenght-1
      ET(i).Enabled=False
   Next
   'Do stuff
   'Load and Change all ET(i).Text....
   MyCalculation()
End Sub

A little ugly and messy but works...

Either way I thought there was some system command that understands
how everything changed at the same time and does not need to call the function 60 times.
 
Upvote 0

danijel

Active Member
Licensed User
Longtime User
Also hard code approach that gets the job done
My program is full of unnecessary IFs, Elses, variables and flags
 
Upvote 0

emexes

Expert
Licensed User
A little ugly and messy but works...
Sounds good... sure beats something beautiful and tidy that doesn't work
Either way I thought there was some system command that understands
how everything changed at the same time and does not need to call the function 60 times.
There is a general concept called throttling (also known by another name that I can't think of right now) but it is something that you have to implement yourself. Happily, it's not that hard to do, assuming timers are not scarce.
 
Upvote 0

danijel

Active Member
Licensed User
Longtime User
sure beats something beautiful and tidy that doesn't work
Or work slow

I just concluded that I like to have control over everything I code,
but at the same time I want the System to think for me.
Double standards!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…