Created
February 2, 2016 02:23
-
-
Save vuhung3990/75033826e97442f61f2d to your computer and use it in GitHub Desktop.
Rxjava for handle event
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
// 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