Skip to content

Instantly share code, notes, and snippets.

@vuhung3990
Created February 2, 2016 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vuhung3990/c3602a679a84da94a239 to your computer and use it in GitHub Desktop.
Save vuhung3990/c3602a679a84da94a239 to your computer and use it in GitHub Desktop.
Rxjava search timer
// search text timer
mEdittext = (EditText) findViewById(R.id.editText);
subTextChange = new Subscriber<CharSequence>() {
@Override
public void onCompleted() {
Log.d(TAG, "onCompleted: ");
}
@Override
public void onError(Throwable e) {
Log.d(TAG, "error: ");
}
@Override
public void onNext(CharSequence charSequence) {
Log.d(TAG, "search: " + charSequence);
}
};
Observable.create(new Observable.OnSubscribe<CharSequence>() {
@Override
public void call(final Subscriber<? super CharSequence> subscriber) {
mEdittext.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) {
subscriber.onNext(s);
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
}).throttleWithTimeout(500, TimeUnit.MILLISECONDS).subscribe(subTextChange);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment