How to trigger an action when user has paused typing for some time in EditText?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
}
};
});