Geo*_*mas 14 android rx-java rx-android
我在编辑文本搜索中使用rxandroid进行去抖操作
我用了
private void setUpText() {
_mSubscription = RxTextView.textChangeEvents(searchStation)//
.debounce(500, TimeUnit.MILLISECONDS)// default Scheduler is Computation
.observeOn(AndroidSchedulers.mainThread())//
.subscribe(getOps().getdata());
}
Run Code Online (Sandbox Code Playgroud)
和观察者一样
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
}
};
}
Run Code Online (Sandbox Code Playgroud)
我的问题是甚至在任何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'
Run Code Online (Sandbox Code Playgroud)
编辑:
它现在可以工作,我在我的逻辑中得到一个空指针获取列表..当我使用onError方法并放置一个堆栈跟踪我发现问题.
如果你想跳过初始调用,那么我们应该将.skip(1)调用 到你的订阅对象.[感谢Daniel Lew ]
上面的代码现在运行得很好
Dan*_*Lew 49
RxTextView.textChanges()发出TextView任何更改之前的当前文本值.请参阅文档.
如果您只想去除更改,那么您应该添加skip(1),这将忽略初始发射:
_mSubscription = RxTextView.textChangeEvents(searchStation)
.skip(1)
.debounce(500, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(getOps().getdata());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8684 次 |
| 最近记录: |