Created
February 2, 2016 03:23
-
-
Save vuhung3990/c3602a679a84da94a239 to your computer and use it in GitHub Desktop.
Rxjava search timer
This file contains 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
// 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