How to trigger an action when user has paused typing for some time in EditText?
Asked
Active
Viewed 1,906 times
1
-
Check this http://stackoverflow.com/questions/10217051/how-to-avoid-multiple-triggers-on-edittext-while-user-is-typing – Jitender Dev Jan 03 '14 at 06:01
1 Answers
8
You can do this:
final Handler mHandler = new Handler();
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
mHandler.removeCallbacksAndMessages(null);
mHandler.postDelayed(userStoppedTyping, 2000); // 2 second
}
Runnable userStoppedTyping = new Runnable() {
@Override
public void run() {
// user didn't typed for 2 seconds, do whatever you want
}
};
});

M-Wajeeh
- 17,204
- 10
- 66
- 103
-
Works Perfect for me. Nice implementation without any usage of Timers, Threads and its complex management. – Satyam Gondhale May 13 '20 at 07:55