0

I have edittext and I want to understand stop and start typing. I listened textwatcher onTextChanged and I use timer for typing.

But when edittext's text is not empty, I don't understand correctly actual typing operation.

I want to see:

My edittext text:

--ad-- --> typing...

--ads-- --> typing...

--ads-- --> after 900 ms stop typing . ::: but not understand

TextWatcher textWatcher = new TextWatcher() {

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, final int before, final int count) {

            if (count != 0 && count >= before) {
                typingTimer.startTyping();
                return;
            }

            typingTimer.stopTyping();

        }
    }; 
begiNNer
  • 128
  • 12

1 Answers1

0

You need a timer in fact.

TextWatcher textWatcher = new TextWatcher() {

    private Timer timer = new Timer();
    private final long TYPING_DELAY = 900; // milliseconds

    public void afterTextChanged(Editable s) {
    }

    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }

    public void onTextChanged(CharSequence s, int start, final int before, final int count) {

        // do what you want
        // show "is typing"

        timer.cancel();
        timer = new Timer();
        timer.schedule(
            new TimerTask() {
                @Override
                public void run() {
                    // here, you're not typing anymore
                }
            }, 
            TYPING_DELAY
        );

    }
}; 
Bruno
  • 3,872
  • 4
  • 20
  • 37