Skip to content

Instantly share code, notes, and snippets.

@patrykpoborca
Created January 16, 2016 00:12
Show Gist options
  • Save patrykpoborca/716c96323fbdb0d82a28 to your computer and use it in GitHub Desktop.
Save patrykpoborca/716c96323fbdb0d82a28 to your computer and use it in GitHub Desktop.
private void debounceWithRx(EditText text){
Observable<CharSequence> editTextStream = RxTextView.textChanges(text);
editTextStream.debounce(500, TimeUnit.MILLISECONDS)
.subscribe(input -> {
//... network request, etc...//
});
}
Handler handler = new Handler();
Runnable runnable;
private void debounceWithoutRx(EditText text){
text.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if(runnable != null){
handler.removeCallbacks(runnable);
}
runnable = new Runnable() {
@Override
public void run() {
//... network request, etc...//
}
};
handler.postDelayed(runnable, 500);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment