E
E
Elsh Yff2015-06-16 16:49:39
Java
Elsh Yff, 2015-06-16 16:49:39

How to listen for changes to an int in RxJava?

There is a variable
int counterr = 0;
There is a loop

for (int i=1;i<100;i++) {
   counter++;           
}

How to use RxJava to listen for changes in counterrand call some function each time?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Emin, 2015-06-16
@Aznix

For reference

PublishSubject<Integer> counterSubject = PublishSubject.create();

counterSubject.subscribe(new Action1<Integer>() {
            @Override public void call(Integer integer) {
                // слушать тут
            }
        });

for (int i=1;i<100;i++) {
   counterSubject.onNext(i);   //менять так        
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question