2

I am using Rxbinding library for detecting clicks on a textview and textchanges in an editbox. I need to have either a textview clicked or a non-empty editbox and to detect that I am using combinelatest operator on two observables as below:

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
        }
    });

The issue is whenever I click on vPriceOnReq(TextView), Statement-1 is not called but only Statement-3 is called. But whenever I enter text in the vProjectBudget(EditText), Statement-2 as well as Statement-3 are always called. Can someone please help me understand what am I doing wrong here.

user2601981
  • 187
  • 2
  • 9

1 Answers1

2

add .replay(1).refCount() to the end of obsPriceOnReq so you'll have:

Observable<Void> obsPriceOnReq = RxView.clicks(vPriceOnReq)
    .asObservable()
    .replay(1)
    .refCount();

and use obsPriceOnReq.withLatestFrom(obsBudget, new Func2<>...) instead of .combineLatest() it will make you app react only for clicks and takes the latest item from obsBudget. About click based events in RxJava

borichellow
  • 1,003
  • 11
  • 11