How can I do something, 0.5 second after text changed in my EditText?

前端 未结 14 1184
渐次进展
渐次进展 2020-12-23 08:49

I am filtering my list using an EditText. I want to filter the list 0.5 second after user has finished typing in EditText. I used the afterTextChanged

14条回答
  •  北海茫月
    2020-12-23 09:46

    You can use RxBindings, it's the best solution. See guide to RxJava operator debounce, I'm sure that will do great in your case.

    RxTextView.textChanges(editTextVariableName)
                .debounce(500, TimeUnit.MILLISECONDS)
                .subscribe(new Action1() {
                    @Override
                    public void call(String value) {
                        // do some work with the updated text
                    }
                });
    

    http://reactivex.io/documentation/operators/debounce.html

提交回复
热议问题