Android Question Handling editText fields

syncmaster13

Member
Licensed User
Longtime User
Hi

I’m trying to find a way how to handle user input to perform calculations without an “enter” button, and in the same time display results in the same editText fields used by user to enter data.

Let’s say I have 3 editTexts inputs. A, B and C. If I enter data to A and B then C should be automatically calculated. For A and C , B is calculated , and for B and C, A is calculated.

Using editText_TextChanged for all inputs is causing infinite loop (that’s what I think)

Is there any other solution to solve that problem?

Thank you
 

DonManfred

Expert
Licensed User
Longtime User
Instead using the textchanged event you can use a short timer (maybe 250/500 ms).
In timer_tick you then can check all three edits to determine which one has to be calculated and do the calculation.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You haven't said what the calculations are so I couldn't test those, but something like the logic in the attached project will solve the infinite loop problem.
 

Attachments

  • EditTextsCalc.zip
    7.9 KB · Views: 125
Upvote 0

syncmaster13

Member
Licensed User
Longtime User
Thank you for ideas. I did test stevel05 sample and unfortunately calculations are a little unpredictable but I learn you can add Text_Changed to one subrutine for all inputs in the same time using sender.

Using timer from DonManfred proposition worked pretty well... until I added 2 more edittexts (5 total) and tried to make a right triangle calculator (as an exercise, not a real project) and I got lost in how to manage which inputs generate results. What I mean is for example: all fields are filled up and I decided to change left side length .

To calculate the rest I need one more entry , hypotenuse or any angle. Since all fields already have some values how the app supposed to know which entry to choose for calculation. ?

It seems making a button “enter” is much simpler with more than 3 edittexts.

Thanks
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It seems making a button “enter” is much simpler with more than 3 edittexts.

Yes, it's usually better to leave it to the user to say when they are ready. Even if you display a result field and the user has to accept that result.
 
Upvote 0
Top