Changing focus on multiple edittext boxes?

I would think checking which view has lost focus is unnecessary, unless the calculations are different depending on which box has lost its focus. If the calculations are the same, just try: public void onFocusChange(View v, boolean hasFocus) { if(!hasFocus) { //do calculations } } If you're only caring that one of the six has lost focus, then any time the focus changes, just check to see if it's not focused, then perform the calculations Also, just for reference, it's more efficient to check if(v.getId() == R.id. Et1) rather than calling findViewById() unnecessarily EDIT: Just thinking, haven't tested this, but something like this also might be more effective, to cause the calculations to occur only if the value was actually changed: private String last; public void onFocusChange(View v, boolean hasFocus) { if(hasFocus) { last = ((EditText)v).getText().toString(); } else { if(!((EditText)v).getText().toString().

Equals(last)) { //do calculations } } }.

I would think checking which view has lost focus is unnecessary, unless the calculations are different depending on which box has lost its focus. If the calculations are the same, just try: public void onFocusChange(View v, boolean hasFocus) { if(!hasFocus) { //do calculations } } If you're only caring that one of the six has lost focus, then any time the focus changes, just check to see if it's not focused, then perform the calculations. Also, just for reference, it's more efficient to check if(v.getId() == R.id.

Et1) rather than calling findViewById() unnecessarily. EDIT: Just thinking, haven't tested this, but something like this also might be more effective, to cause the calculations to occur only if the value was actually changed: private String last; public void onFocusChange(View v, boolean hasFocus) { if(hasFocus) { last = ((EditText)v).getText().toString(); } else { if(!((EditText)v).getText().toString(). Equals(last)) { //do calculations } } }.

Thanks for the code cleaning ideas. – Ted Betz Feb 17 at 20:23.

You would probably only want to make changes if the text actually changed. So you should add a TextChangedListener for your edittexts. So for each of your edit text's: et1.

AddTextChangedListener(this); ... et6. AddTextChangedListener(this); Then, let your class implement TextWatcher @Override public void afterTextChanged(Editable s) { // do calculations } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { }.

Clever! Thanks. – Ted Betz Feb 17 at 20:22.

I've written some code to test if a user has changed the values in any of 6 edittext boxes, but the code looks bulky and redundant. I'm wondering if there is a more elegant way to do this. The user inputs numbers into all of 6 edittext boxes, and after each entry, a calculation routine checks to be sure all boxes have valid numbers before doing the calculation.

The kistener has to fire on a lost foucus so that the number is in the box before the calculations are done. And outputing a result. If the user want to go back and change a value in any one of the 6 edittext boxes, the calulation routine runs again.

I've set up 6 listeners in the onCreate section for each edittext box. Then I have 6 separate routines to test for each hasFocus==false. Then I have a method to check if any edittext box has lost focus, suggesting theat the user changed some data, and therfore re-run the calulations.

Forgive me if I've made any typos in the code above. It runs on my platform, but I would like to learn a better way to do this.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions