@Override
protected void onResume() {
super.onResume();
// Listen to key presses and only start search after user paused to avoid excessive redrawing on the screen.
disposable = RxTextView.textChangeEvents(searchInputView)
.debounce(200, TimeUnit.MILLISECONDS) // default Scheduler is Schedulers.computation()
.observeOn(AndroidSchedulers.mainThread()) // Needed to access Realm data
.toFlowable(BackpressureStrategy.BUFFER)
.switchMap(textChangeEvent -> {
// Use Async API to move Realm queries off the main thread.
// Realm currently doesn't support the standard Schedulers.
return realm.where(Person.class)
.beginsWith("name", textChangeEvent.text().toString())
.findAllSortedAsync("name")
.asFlowable();
})
// Only continue once data is actually loaded
// RealmObservables will emit the unloaded (empty) list as its first item
.filter(people -> people.isLoaded())
.subscribe(people -> {
searchResultsView.removeAllViews();
for (Person person : people) {
TextView view = new TextView(ThrottleSearchActivity.this);
view.setText(person.getName());
searchResultsView.addView(view);
}
}, throwable -> throwable.printStackTrace());
}
ThrottleSearchActivity.java 文件源码
java
阅读 37
收藏 0
点赞 0
评论 0
项目:GitHub
作者:
评论列表
文章目录