I have an EditText field in my layout. I want to perform an action when the user stops typing in that edittext field. I have implemented TextWatcher and use its functions >
I used a CountDownTimer to find out if the user stopped typing after a while. I hope to help.
yourEditText.addTextChangedListener(new TextWatcher() {
CountDownTimer timer = null;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (timer != null) {
timer.cancel();
}
timer = new CountDownTimer(1500, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
//do what you wish
}
}.start();
}
@Override
public void afterTextChanged(Editable s) {
}
});