📌  相关文章
📜  在 2 秒更改 android 上编辑文本 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:29.396000             🧑  作者: Mango

代码示例1
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) { }

        private Timer timer=new Timer();
        private final long DELAY = 1000; // milliseconds

        @Override
        public void afterTextChanged(final Editable s) {
            timer.cancel();
            timer = new Timer();
            timer.schedule(
                new TimerTask() {
                    @Override
                    public void run() {
                        // TODO: do what you need here (refresh list)
                        // you will probably need to use runOnUiThread(Runnable action) for some specific actions (e.g. manipulating views)
                    }
                }, 
                DELAY
            );
        }
    }
);