app的build.gradle,导入Rxjava库
implementation : "io.reactivex:rxjava:1.2.10"
1.新建xxxSubscribe类实现Observable.OnSubscribe<View>
private static final String TAG = "ClickSubscribe";
private Subscriber mSubscriber;
public ClickSubscribe(View view) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LogUtils.e(TAG, v.getClass().getSimpleName() + "我被点击了");
mSubscriber.onNext(v);
}
});
}
@Override
public void call(Subscriber<? super View> subscriber) {
mSubscriber = subscriber;
}
2.运用操作符
throttleFirst(time,TimeUnit.SECONDS)
如下方式
Observable.create(new ClickSubscribe(nextBtn))
.throttleFirst(2, TimeUnit.SECONDS)
.subscribe(new Action1<View>() {
//todo dothing
}
网友评论