Comments (3)
可以的,我们可以模拟两个按钮对映两个被订阅者,并在点击时分别为同一个订阅者发出数据,那么这个订阅者就有责任去区分数据来自于何方,并分别处理,大致代码如下:
//被订阅者1 @OnClick(R.id.btn1) void btn1() { Observable.just(1) .compose(this.<Integer>bindToLifecycle()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(mReuseSubscriber); }
//被订阅者2 @OnClick(R.id.btn2) void btn2() { Observable.just("string") .compose(this.<String>bindToLifecycle()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(mReuseSubscriber); }
`
//订阅者
mReuseSubscriber = new Observer() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Object data) {
if (data.getClass() == Integer.class) {
Toast.makeText(getActivity(), "The data from Btn1!", Toast.LENGTH_SHORT).show();
} else if (data.getClass() == String.class) {
Toast.makeText(getActivity(), "The data from Btn2!", Toast.LENGTH_SHORT).show();
}
}
};
`
from rxjava_for_android.
btn1重复点击多次,mReuseSubscriber 每次都可以响应吗???我是结合Retrofit使用的。subscriber是一个成员变量,我第一次请求可以处理,但是再次请求时subscriber就不响应了,不知道是不是Retrofit的问题。
from rxjava_for_android.
根据你所说的猜想应该是Retrofit问题,你可以阅读这篇文章: Retrofit 2.0,在**Call (10:30)**这部分或许会对你有所帮助
from rxjava_for_android.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxjava_for_android.