-
-
Save pyadav/2e828238777abd2c3c8a829c3f5b7e44 to your computer and use it in GitHub Desktop.
Rxjava for handle event
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
| // sample 3 UI event | |
| mButton = (Button) findViewById(R.id.button); | |
| Observable<View> clickEventObservable = Observable.create(new Observable.OnSubscribe<View>() { | |
| @Override | |
| public void call(final Subscriber<? super View> subscriber) { | |
| mButton.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| subscriber.onNext(v); | |
| } | |
| }); | |
| } | |
| }); | |
| clickEventObservable.subscribe(new Subscriber<View>() { | |
| @Override | |
| public void onCompleted() { | |
| Log.d(TAG, "onCompleted: "); | |
| } | |
| @Override | |
| public void onError(Throwable e) { | |
| Log.d(TAG, "onError: "+e.getMessage()); | |
| } | |
| @Override | |
| public void onNext(View view) { | |
| Log.d(TAG, "onNext: clicked"); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment