title: Passing variable to paging library class
body: <p>I am creating an app with Android Paging Library. I'm using retrofit with it. 
  Retrofit code is in ItemDataSource and there i can't pass variable to it. I have some variable coming with intent. How can i set my variable in Retrofit Post method.</p>
  
  <p>ItemDataSource</p>
  
  <pre><code>public class ItemDataSource extends PageKeyedDataSource&lt;Integer, Item&gt; {
  //we will start from the first page which is 1
  private static final int PAGE_NUMBER = 1;
  //this will be called once to load the initial data
  String table
  ItemDataSource(String table){
  this.table = table;
  }
  @Override
  public void loadInitial(@NonNull LoadInitialParams&lt;Integer&gt; params, @NonNull 
  final LoadInitialCallback&lt;Integer, Item&gt; callback) {
  
     RetrofitClient.getInstance()
        // I want to pass table variable here.
              .getApi().getAnswers("table","","","",PAGE_NUMBER,"")
              .enqueue(new Callback&lt;StackApiResponse&gt;() {
                  @Override
                  public void onResponse(Call&lt;StackApiResponse&gt; call, 
                      Response&lt;StackApiResponse&gt; response) {
                      if (response.body() != null) {
                          callback.onResult(response.body().images, null, 
                   PAGE_NUMBER + 1);
                      }
                  }
  
                  @Override
                  public void onFailure(Call&lt;StackApiResponse&gt; call, 
    Throwable 
                     t) {
  
                  }
              });
                 }
              }
  </code></pre>
  
  <p>Main Activity</p>
  
  <pre><code>    public class Detail extends AppCompatActivity {
      ArrayList&lt;Item&gt; items;
      Api api;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_detail);
        // I'm getting intent here.
          final     RecyclerView recyclerView = 
          findViewById(R.id.recyclerview);
           recyclerView.setLayoutManager(new LinearLayoutManager(this));
          recyclerView.setHasFixedSize(true);
          ItemViewModel itemViewModel = 
         ViewModelProviders.of(this).get(ItemViewModel.class);
  
          //creating the Adapter
  
          //observing the itemPagedList from view model
          itemViewModel.itemPagedList.observe(this, new 
         Observer&lt;PagedList&lt;Item&gt;&gt;() {
              @Override
              public void onChanged(@Nullable PagedList&lt;Item&gt; items) {
  
                  //in case of any changes
                  //submitting the items to adapter
                  adapter.submitList(items);
              }
          });
  
          //setting the adapter
          recyclerView.setAdapter(adapter);
  
      }
   }
  </code></pre>
  
  <p>Item View Model</p>
  
  <pre><code>public class ItemViewModel extends ViewModel {
  
  //creating livedata for PagedList  and PagedKeyedDataSource
  LiveData&lt;PagedList&lt;Item&gt;&gt; itemPagedList;
  LiveData&lt;PageKeyedDataSource&lt;Integer, Item&gt;&gt; liveDataSource;
  
  //constructor
  public ItemViewModel() {
      //getting our data source factory
      ItemDataSourceFactory itemDataSourceFactory = new 
   ItemDataSourceFactory();
  
      //getting the live data source from data source factory
      liveDataSource = itemDataSourceFactory.getItemLiveDataSource();
  
      //Getting PagedList config
      PagedList.Config pagedListConfig =
              (new PagedList.Config.Builder())
                      .setEnablePlaceholders(false)
                      .setPageSize(10).build();
  
      //Building the paged list
      itemPagedList = (new LivePagedListBuilder(itemDataSourceFactory, 
   pagedListConfig))
              .build();
   }
  </code></pre>
  
  <p>}</p>
  
  <p>BTW i'm following this <a href="https://www.simplifiedcoding.net/android-paging-library-tutorial/" rel="nofollow noreferrer">https://www.simplifiedcoding.net/android-paging-library-tutorial/</a></p>