Created
January 16, 2016 00:12
-
-
Save patrykpoborca/716c96323fbdb0d82a28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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