Knowing when Edit text is done being edited

Matt picture Matt · Feb 24, 2011 · Viewed 98.4k times · Source

How do I know when my edit text is done being edited? Like when the user selects the next box, or presses the done button on the soft keyboard.

I want to know this so I can clamp the input. It looks like text watcher's afterTextChanged happens after each character is entered. I need to do some calculations with the input, so I would like to avoid doing the calculation after each character is entered.

thanks

Answer

Reno picture Reno · Feb 24, 2011

By using something like this

 meditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            switch (actionId){
                case EditorInfo.IME_ACTION_DONE:
                case EditorInfo.IME_ACTION_NEXT:
                case EditorInfo.IME_ACTION_PREVIOUS:
                    yourcalc();
                    return true;
            }
            return false;
        }
    });