AZR34L
AZR34L

Reputation: 73

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>>. How do I change that to only java.util.list<GameModel>?

Upvotes: 1

Views: 57

Answers (1)

R. Zag&#243;rski
R. Zag&#243;rski

Reputation: 20258

You don't properly understand what is an Observable.
It is an object, to which You can subscribe() to get the result of it's operation. Usually, only when subscribing to an Observable it starts and you can get the result inside Subscriber's onNext() function.
So in your case:

  1. Subscribe to this Observable.
  2. Look for the result inside this subscriber's onNext function.

    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) { }
    )
    

Upvotes: 1

Related Questions