I have an EditText field in my layout. I want to perform an action when the user stops typing in that edittext field. I have implemented TextWatcher and use its functions >
There is a very simple and easy way of doing this using RxBindings
for Android,
Get the library if you haven't already,
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
Add and modify this snippet to your needs,
RxTextView.textChanges(mEditText)
.debounce(3, TimeUnit.SECONDS)
.subscribe(textChanged -> {
Log.d("TAG", "Stopped typing!");
});
What is Debounce Operator? - Learn more about it here
In our context, debounce will only notify you of the text change inside the EditText
after a certain time has passed from the last text change that occurred inside the EditText
.
Here I am waiting for 3 seconds until the last text change happened to conclude that the user has stopped typing. You can modify it according to your needs.