how to know when user is done typing android

Solutions on MaxInterview for how to know when user is done typing android by the best coders in the world

showing results for - "how to know when user is done typing android"
Federica
18 Jul 2019
1long delay = 1000; // 1 seconds after user stops typing
2long last_text_edit = 0;
3Handler handler = new Handler();
4
5private Runnable input_finish_checker = new Runnable() {
6    public void run() {
7        if (System.currentTimeMillis() > (last_text_edit + delay - 500)) {
8            // TODO: do what you need here
9            // ............
10            // ............
11            DoStuff();
12        }
13    }
14};
15
16EditText editText = (EditText) findViewById(R.id.editTextStopId);
17editText.addTextChangedListener(new TextWatcher() {
18    @Override
19    public void beforeTextChanged (CharSequence s,int start, int count,
20    int after){
21    }
22    @Override
23    public void onTextChanged ( final CharSequence s, int start, int before,
24    int count){
25        //You need to remove this to run only once
26        handler.removeCallbacks(input_finish_checker);
27
28    }
29    @Override
30    public void afterTextChanged ( final Editable s){
31        //avoid triggering event when text is empty
32        if (s.length() > 0) {
33            last_text_edit = System.currentTimeMillis();
34            handler.postDelayed(input_finish_checker, delay);
35        } else {
36
37        }
38    }
39}
40
41);