title: Firebase database pagination
body: <p>I need know how to load data dynamically on scrolling with Firebase.  I want to get the latest records from Firebase at limit 50. After reach this limit, I will download the next 50 data.</p>
  
  <p><strong>MarkerActivity.java</strong></p>
  
  <pre><code>public class MarkerActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
  
  
      private LinearLayoutManager layoutManager;
      private ViewSwitcher mViewSwitcher;
      private MarkerAdapter mMarkerAdapter;
      private RecyclerView recyclerView
      private int page_number = 1;
      private int item_count = 10;
      private boolean isLoading = true;
      private int pastVisibleItems, visibleItemCount,totallItemCount,previous_totall = 0;
      private int view_threshold = 10;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_markers);
          recyclerView = findViewById(R.id.recycler_view);
          layoutManager = new LinearLayoutManager(this);
          recyclerView.setHasFixedSize(true);
          recyclerView.setLayoutManager(layoutManager);
          recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
              @Override
              public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                  super.onScrolled(recyclerView, dx, dy);
  
                  visibleItemCount = layoutManager.getChildCount();
                  totallItemCount = layoutManager.getItemCount();
                  pastVisibleItems = layoutManager.findLastVisibleItemPosition();
  
                  if (dy&gt;0)
                  {
                      if (isLoading)
                      {
                          if (totallItemCount&gt;previous_totall)
                          {
                              isLoading = false;
                              previous_totall = totallItemCount;
                          }
                      }
  
                      if (!isLoading&amp;&amp;(totallItemCount-visibleItemCount)&lt;=(pastVisibleItems=view_threshold))
                      {
                          page_number++;
                          isLoading = true;
                      }}
          });
      }
  }
  </code></pre>
  
  <p>Could you help me?</p>