title: Paging Library & Room : Content not loading when Recyclerview scroll
body: <p>I'm trying to implement endless scrolling with recyclerview and Room using Paging Library in my application According to this article: <a href="https://developer.android.com/topic/libraries/architecture/paging/#database-examples" rel="nofollow noreferrer">https://developer.android.com/topic/libraries/architecture/paging/#database-examples</a></p>
  
  <p>Some of the data is loaded at initialization but when user scroll, nothing happens, the rest of the data is not fetched</p>
  
  <p>My Dao</p>
  
  <pre><code>@Dao
  public interface MessageDao {
      .
      .
      .
      @Query("SELECT * FROM messages ORDER BY created DESC")
      DataSource.Factory&lt;Integer, Message&gt; getPagedMessage();
  }
  </code></pre>
  
  <p>ViewModel</p>
  
  <pre><code>public class SmsViewModel extends AndroidViewModel {
  
      private LiveData&lt;PagedList&lt;Message&gt;&gt; liveData;
  
      public SmsViewModel(@NonNull Application application) {
          super(application);
  
          DataSource.Factory&lt;Integer, Message&gt; factory = AppDatabase.getInstance(getApplication()).messageDao().getPagedMessage();
  
          PagedList.Config config = (new PagedList.Config.Builder())
                  .setPageSize(10)
                  .setInitialLoadSizeHint(20)
                  .setPrefetchDistance(5)
                  .setEnablePlaceholders(false)
                  .build();
          liveData = new LivePagedListBuilder&lt;&gt;(factory, config).build();
      }
  
      public LiveData&lt;PagedList&lt;Message&gt;&gt; getLiveData() {
          return liveData;
      }
  } 
  </code></pre>
  
  <p>Adapter class</p>
  
  <pre><code>public abstract class BasePagedAdapter&lt;T&gt; extends PagedListAdapter&lt;T, BasePagedAdapter.MyViewHolder&gt; {
  
      private OnClickListener onClickListener;
      private OnLongClickListener onLongClickListener;
  
      public BasePagedAdapter(DiffUtil.ItemCallback&lt;T&gt; callback) {
          super(callback);
      }
  
      public void setOnClickListener(OnClickListener onClickListener) {
          this.onClickListener = onClickListener;
      }
  
      public void setOnLongClickListener(OnLongClickListener onLongClickListener) {
          this.onLongClickListener = onLongClickListener;
      }
  
      @NonNull
      @Override
      public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  
          LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
          ViewDataBinding binding = DataBindingUtil.inflate(layoutInflater, getLayoutIdForType(viewType), parent, false);
          return new MyViewHolder(binding);
      }
  
      @Override
      public void onBindViewHolder(@NonNull BasePagedAdapter.MyViewHolder holder, int position) {
          T t = getDataAtPosition(position);
          holder.bind(t);
      }
  
      public abstract T getDataAtPosition(int position);
  
      abstract @LayoutRes
      public int getLayoutIdForType(int viewType);
  
      class MyViewHolder extends RecyclerView.ViewHolder {
          private final ViewDataBinding binding;
  
          MyViewHolder(ViewDataBinding binding) {
              super(binding.getRoot());
              this.binding = binding;
  
              itemView.setOnClickListener(v -&gt; {
                  if (onClickListener != null) {
                      onClickListener.onClick(getAdapterPosition());
                  }
              });
  
              itemView.setOnLongClickListener(view -&gt; {
                  if(onLongClickListener != null) {
                      onLongClickListener.onLongClick(getAdapterPosition());
                      return true;
                  }
                  return false;
              });
          }
  
          void bind(T obj) {
              binding.setVariable(BR.obj, obj);
              binding.executePendingBindings();
          }
      }
  
      public interface OnClickListener {
          void onClick(int position);
      }
  
      public interface OnLongClickListener {
          void onLongClick(int position);
      }
  }
  </code></pre>
  
  <p>Activity </p>
  
  <pre><code>public class SmsActivity extends AppCompatActivity {
  
      @BindView(R.id.lyt_empty)
      View lytEmpty;
  
      @BindView(R.id.progressBar)
      ProgressBar progressBar;
  
      @BindView(R.id.recycler_view)
      RecyclerView recyclerView;
  
      PagedList&lt;Message&gt; messages;
  
      BasePagedAdapter&lt;Message&gt; adapter = new BasePagedAdapter&lt;Message&gt;(DIFF_CALLBACK) {
          @Override
          public Message getDataAtPosition(int position) {
              if (messages != null) {
                  return messages.get(position);
              }
              return null;
          }
  
          @Override
          public int getLayoutIdForType(int viewType) {
              return R.layout.item_sms_list;
          }
      };
  
  
      SmsViewModel viewModel;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_sms);
  
          Toolbar toolbar = findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
          //noinspection ConstantConditions
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          ButterKnife.bind(this);
  
          viewModel = ViewModelProviders.of(this).get(SmsViewModel.class);
  
          adapter.setOnClickListener(position -&gt; {
              Intent intent = new Intent(this, SmsDetailActivity.class);
              intent.putExtra(SmsDetailActivity.EXTRA_SMS, messages.get(position));
              startActivity(intent);
          });
          recyclerView.setAdapter(adapter);
          recyclerView.setNestedScrollingEnabled(false);
          loadData();
      }
  
      private void loadData() {
          viewModel.getLiveData().observe(this, messages -&gt; {
              progressBar.setVisibility(View.GONE);
              this.messages = messages;
              if (messages != null &amp;&amp; messages.size() &gt; 0) {
                  adapter.submitList(messages);
                  recyclerView.setVisibility(View.VISIBLE);
                  lytEmpty.setVisibility(View.GONE);
              } else {
                  recyclerView.setVisibility(View.GONE);
                  lytEmpty.setVisibility(View.VISIBLE);
              }
          });
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.menu_sms_list, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          if (item.getItemId() == android.R.id.home) {
              finish();
          }
          return true;
      }
  
  
      private static DiffUtil.ItemCallback&lt;Message&gt; DIFF_CALLBACK =
              new DiffUtil.ItemCallback&lt;Message&gt;() {
                  @Override
                  public boolean areItemsTheSame(Message oldItem, Message newItem) {
                      return oldItem.uid == newItem.uid;
                  }
  
                  @Override
                  public boolean areContentsTheSame(Message oldItem, @NonNull Message newItem) {
                      return oldItem.equals(newItem);
                  }
              };
  }
  </code></pre>
  
  <p>There are currently 25 elements in the message table but only 20 are displayed at initialization. When I scroll the Recyclerview nothing happens the other 5 elements are not displayed</p>