title: Paging Library without Room
body: <p>All examples of the new paging library have been with Room library and Room creates a Data Source for us. In my own case, I need to create my custom data source.</p>
  
  <p>Here is a method in my view model class that ought to return the live data. My livedata always returns null.</p>
  
  <pre><code> LiveData&lt;PagedList&lt;ApiResult&gt;&gt; getData(){
  
      LivePagedListProvider&lt;Integer,ApiResult&gt; p = new LivePagedListProvider&lt;Integer, ApiResult&gt;() {
          @Override
          protected DataSource&lt;Integer, ApiResult&gt; createDataSource() {
              return new DataClass();
          }
  
      };
  
      listLiveData = p.create(0,new PagedList.Config.Builder()
              .setPageSize(5) //number of items loaded at once
              .setPrefetchDistance(0)// the distance to the end of already loaded list before new data is loaded
              .build());
      return listLiveData;
  }
  </code></pre>
  
  <p>And here is the Data class</p>
  
  <pre><code>public class DataClass extends TiledDataSource&lt;ApiResult&gt; {
  
      private List&lt;ApiResult&gt; result = new ArrayList&lt;&gt;();
  
      @Override
      public int countItems() {
          return result.size();
      }
  
      @Override
      public List&lt;ApiResult&gt; loadRange(int startPosition, int count) {
  
          Call&lt;String&gt; call = NetworkModule.providesWebService().makeRequest();
          call.enqueue(new Callback&lt;String&gt;() {
              @Override
              public void onResponse(@NonNull Call&lt;String&gt; call, @NonNull Response&lt;String&gt; response) {
                  Log.i(DataClass.this.getClass().getSimpleName() + " - onResponse", String.valueOf(response));
                  result = parseJson(response.body());
              }
  
              @Override
              public void onFailure(@NonNull Call&lt;String&gt; call, @NonNull Throwable t) {
                  Log.i(DataClass.this.getClass().getSimpleName() + " - onFailure", t.getMessage());
              }
  
          });
  
          return result;
      }
  
  }
  </code></pre>