2017-04-10 16 views
2

跳出搜索輸入值,我想用switchMap()與方法返回Flowable<List<T>>我已經編輯我的代碼使用什麼@Maxim Ostrovidov建議,現在與debounce我添加了3行,因爲想要去列表轉換爲其他時間和收到名單,但不起作用。我用它的工作原理其他情況下,這些三線,而與debounceswitchMap如何使用帶有Flowable數據的RxTextView switchMap?

.flatMapIterable(items -> items) 
     .map(Product::fromApi) 
     .toList() 




    subscription = RxTextView.textChangeEvents(searchInput) 
      .toFlowable(BackpressureStrategy.BUFFER) 
      .debounce(400, TimeUnit.MILLISECONDS) 
      .observeOn(Schedulers.computation()) 
      .switchMap(event -> getItems(searchInput.getText().toString())) 
      .flatMapIterable(items -> items) 
      .map(Product::fromApi) 
      .toList() 
      .subscribeOn(Schedulers.io()) 
      .observeOn(AndroidSchedulers.mainThread()) 
     .subscribe(/../); 

回答

2

因爲沒有Observable.switchMapFlowable操作yet,你必須使用toObservabletoFlowable手動轉換您的流(取決於什麼類型的流你打算最終得到):

// Observable stream 
RxTextView.textChangeEvents(searchInput) 
    .debounce(300, TimeUnit.MICROSECONDS) 
    .switchMap(event -> yourFlowable(event).toObservable()) 
    ... 

// Flowable stream 
RxTextView.textChangeEvents(searchInput) 
    .toFlowable(BackpressureStrategy.BUFFER) //or any other strategy 
    .debounce(300, TimeUnit.MICROSECONDS) 
    .switchMap(event -> yourFlowable(event)) 
    ... 
相關問題