Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delay not working for ViewObservable? #5

Closed
finian opened this issue Aug 26, 2014 · 2 comments
Closed

delay not working for ViewObservable? #5

finian opened this issue Aug 26, 2014 · 2 comments

Comments

@finian
Copy link

finian commented Aug 26, 2014

Sample codes below:

EditText editText = ...
ViewObservable.text(editText)
    .delay(1000, TimeUnit.MILLISECONDS)
    .subscribe(new Action1<EditText>() {
      @Override
      public void call(EditText editText) {
        Log.d("TAG", editText.getText().toString());
      }
    });

Nothing printed out as I type in the editText. But if I comment out the delay line, everything works fine. am I missing something?

@Yarikx
Copy link
Contributor

Yarikx commented Aug 26, 2014

It's probably the issue with the main thread. action after delay is executed on computation scheduler (see https://github.com/ReactiveX/RxJava/wiki/Scheduler#default-schedulers-for-rxjava-observable-operators)
So you end up working with view not from main thread.

Try to put .observeOn(AndroidSchedulers.mainThread()) after delay line.

Update: or you can retrieve text value from EditText via map operator before the delay

@finian
Copy link
Author

finian commented Aug 26, 2014

@Yarikx 👍 Thx! Problem solved :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants