我正在使用 Rxbinding 库来检测对文本视图的点击和编辑框中的文本更改。我需要单击文本视图或非空编辑框,并检测我在两个可观察对象上使用 combinelatest 运算符,如下所示:
Observable<Void> obsPriceOnReq = RxView.clicks(vPriceOnReq).asObservable();
obsPriceOnReq.subscribe(new Action1<Void>() {
@Override
public void call(Void aVoid) {
mPriceOnReqBool = !mPriceOnReqBool; // Statement-1
// Do some work here.
});
Observable<String> obsBudget = RxTextView.textChanges(vProjectBudget).map(charseqToStr);
obsBudget.subscribe(new Action1<String>() {
@Override
public void call(String s) {
mBudgetFilledBool = checkPosDouble(s); // Statement-2
}
});
Observable.combineLatest(obsPriceOnReq, obsBudget, new Func2<Void, String, Boolean>() {
@Override
public Boolean call(Void aVoid, String s) {
return mBudgetFilledBool || mPriceOnReqBool; // Statement-3
}
}).subscribe(new Action1<Boolean>() {
@Override
public void call(Boolean aBoolean) {
// Do some work here
}
});
问题是每当我单击vPriceOnReq (TextView) 时,不会调用Statement-1,而只调用Statement-3。但每当我在vProjectBudget (EditText)中输入文本时,总会调用Statement-2和Statement-3。有人可以帮我理解我在这里做错了什么。