code: private void initGrid() {
          // Setting up images grid
          final int cols = getResources().getInteger(R.integer.images_grid_columns);
  
          views.grid.setLayoutManager(new GridLayoutManager(this, cols));
  
          gridAdapter = new PhotoListAdapter(this);
          gridAdapter.setLoadingOffset(PAGE_SIZE / 2);
          gridAdapter.setCallbacks(new EndlessRecyclerAdapter.LoaderCallbacks() {
              @Override
              public boolean canLoadNextItems() {
                  return gridAdapter.canLoadNext();
              }
  
              @Override
              public void loadNextItems() {
                  // We should either load all items that were loaded before state save / restore,
                  // or next page if we already loaded all previously shown items
                  int count = Math.max(savedPhotoCount, gridAdapter.getCount() + PAGE_SIZE);
                  Events.create(FlickrApi.LOAD_IMAGES_EVENT).param(count).post();
              }
          });
          views.grid.setAdapter(gridAdapter);
      }
docs: Initializing grid view (RecyclerView) and endless loading.