edittext listener text finished code example
Example: how to know when user is done typing android
long delay = 1000;
long last_text_edit = 0;
Handler handler = new Handler();
private Runnable input_finish_checker = new Runnable() {
public void run() {
if (System.currentTimeMillis() > (last_text_edit + delay - 500)) {
DoStuff();
}
}
};
EditText editText = (EditText) findViewById(R.id.editTextStopId);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged (CharSequence s,int start, int count,
int after){
}
@Override
public void onTextChanged ( final CharSequence s, int start, int before,
int count){
handler.removeCallbacks(input_finish_checker);
}
@Override
public void afterTextChanged ( final Editable s){
if (s.length() > 0) {
last_text_edit = System.currentTimeMillis();
handler.postDelayed(input_finish_checker, delay);
} else {
}
}
}
);