简体   繁体   English

如何更改rx.Observable <java.util.list<T> &gt;到java.util.list <T>

[英]How do I change rx.Observable<java.util.list<T>> to java.util.list<T>

Declaration 宣言

@GET("api/Game/SearchGames")
Observable<List<GameModel>> searchGames();

This is the network call 这是网络电话

public static Observable<List<GameModel>> searchGames () {
    VersusAPI client = VersusServiceGenerator.createService(VersusAPI.class);
    Observable<List<GameModel>> ob = client.searchGames();
    return ob;
}

Here is where I implement. 这是我实施的地方。

mAdapterMyGames = new RecyclerViewAdapter(searchGames());

searchGames() returns rx.Observable<java.util.list<GameModel>> . searchGames()返回rx.Observable<java.util.list<GameModel>> How do I change that to only java.util.list<GameModel> ? 如何将其更改为仅java.util.list<GameModel>

You don't properly understand what is an Observable . 您无法正确理解什么是Observable
It is an object, to which You can subscribe() to get the result of it's operation. 它是一个对象,您可以subscribe()以获取其操作的结果。 Usually, only when subscribing to an Observable it starts and you can get the result inside Subscriber 's onNext() function. 通常,只有在订阅Observable它才会启动,您可以在SubscriberonNext()函数中获取结果。
So in your case: 所以在你的情况下:

  1. Subscribe to this Observable . 订阅此Observable
  2. Look for the result inside this subscriber's onNext function. 在此订户的onNext函数中查找结果。

     searchGames().subscribe(new new Subscriber<List<GameModel>>() { @Override public void onNext(List<GameModel> gameModels) { //TODO make sth useful with models } @Override public void onCompleted() { } @Override public void onError(Throwable e) { } ) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM