在文本更改事件之前自动调用 RxAndroid textview 事件

RxAndroid textview events called automatically before text change events

我使用 rxandroid 对 edittext 搜索进行去抖动操作

我用过

private void setUpText() {
        _mSubscription = RxTextView.textChangeEvents(searchStation)//
                .debounce(500, TimeUnit.MILLISECONDS)// default Scheduler is Computation
                .observeOn(AndroidSchedulers.mainThread())//
                .subscribe(getOps().getdata());
    }

观察者为

public Observer<TextViewTextChangeEvent> getdata()
    {

        return new Observer<TextViewTextChangeEvent>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                 e.printStackTrace();
            }

            @Override
            public void onNext(TextViewTextChangeEvent onTextChangeEvent) {
//                stationsugession(onTextChangeEvent.text().toString());

                //here i called link to get the data from the server
            }
        };
    }

我的问题是 link 甚至在任何 edittext 更改发生之前就被调用了。 它不调用 textchange 事件。 我错过了什么吗 我在这里做错了什么。我是 rxandroid 和 rxjava 的新手。

我用过

  compile 'io.reactivex:rxandroid:1.1.0'
    compile 'io.reactivex:rxjava:1.1.0'
    compile 'com.jakewharton.rxbinding:rxbinding:0.2.0'

编辑:

它现在可以工作了,我在获取列表的逻辑中得到了一个空指针.. 当我使用 onError 方法并放置堆栈跟踪时,我发现了问题。

如果您想跳过初始调用,那么我们应该调用 .skip(1) 到您的订阅对象。 [感谢 Daniel Lew]

上面的代码现在可以完美运行了

RxTextView.textChanges() 在发出任何更改之前发出 TextView 的当前文本值。参见 the documentation

如果你只想对变化进行去抖动,那么你应该添加 skip(1),这将忽略初始发射:

_mSubscription = RxTextView.textChangeEvents(searchStation)
    .skip(1)
    .debounce(500, TimeUnit.MILLISECONDS)
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(getOps().getdata());