edit text on 2sec change andropid

Solutions on MaxInterview for edit text on 2sec change andropid by the best coders in the world

showing results for - "edit text on 2sec change andropid"
Sofia
29 Oct 2020
1editText.addTextChangedListener(
2    new TextWatcher() {
3        @Override public void onTextChanged(CharSequence s, int start, int before, int count) { }
4        @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
5
6        private Timer timer=new Timer();
7        private final long DELAY = 1000; // milliseconds
8
9        @Override
10        public void afterTextChanged(final Editable s) {
11            timer.cancel();
12            timer = new Timer();
13            timer.schedule(
14                new TimerTask() {
15                    @Override
16                    public void run() {
17                        // TODO: do what you need here (refresh list)
18                        // you will probably need to use runOnUiThread(Runnable action) for some specific actions (e.g. manipulating views)
19                    }
20                }, 
21                DELAY
22            );
23        }
24    }
25);
26