0

I have a page in my app where I have a lot of EditTexts.

Actually it's a ListView, with rows containing EditTexts, so the number of EditTexts is dynamic.

Normally users fill EditTexts they want, then press a Save button and we are done. My problem is, some user forgot to leave the 'last' EditText, they just press the Save button, and this last EditText won't be saved. Because I use OnFocusChangeListeners to validate.

I don't want to check (again) all the EditTexts when the Save button was pressed, so what can I do?

Can I get where was the focus when I pressed a button? And then I only validate this EditText, not all of them.

2
  • Can you use a text watcher to validate your edit texts?
    – Lena Bru
    Jul 1, 2014 at 13:56
  • Hmm, I never used TextWatchers earlier. As I see now, it is something like that 'online validation', I mean u don't need to left your EditText to validate. Thanks for this tip, u will get my up if it works.
    – Rezmalac
    Jul 1, 2014 at 14:05

2 Answers 2

0

In your button on click listener, you can use getCurrentFocus() to get the currently focused view. Then just check if its an EditText and validate it.

1
  • Oh, the magic getCurrentFocus()! :) More easier then the other, thank u very much!
    – Rezmalac
    Jul 1, 2014 at 14:32
0

Try using a TextWatcher to validate your EditTexts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.