18

I build an android application. I have an EditText. I want to save changes (or anything else) automatically after the user change the text. Now I use

editText.addTextChangedListener(textWatcher);

and

  TextWatcher textWatcher = new TextWatcher() {
    public void afterTextChanged(Editable s) {
     ...
    }

But it saves the changes after every little change (add \ remove a letter), and I want that it'll be saved only after the user finished (closed the keyboard, clicked on a different edittext, etc. ). How can I do that?

TamarG
  • 3,522
  • 12
  • 44
  • 74

1 Answers1

1

As Kotlin is now official android language:

var editText = findViewById<EditText>(R.id.editText) 

editText.onFocusChangeListener = OnFocusChangeListener { _, hasFocus ->
        if (!hasFocus) { 
           //SAVE THE DATA       
        }
}
SkorpEN
  • 2,491
  • 1
  • 22
  • 28