title: Limit recycler view to a particular number of child views and load when scrolled to bottom
body: <p>I have nearly 100-120 data stored in my sqlite db(android). 
  I have done extracting the data to recycler view and showed up in a layout but how can i make the recycler view to load only 20 nos of data from the database and when the page is scrolled to bottom it again fetches the next 20 items and append it with the 20 item and show 40 items, till all the data loading gets completed. </p>
  
  <p><strong>Here is my Code.</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  RecyclerView recycler;
  private LinearLayoutManager mLayoutManager;
  private BranchAdapter mAdapter;
  private  static MyDatabase db;
  private static SQLiteDatabase sdb;
  
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      recycler= (RecyclerView)findViewById(R.id.maiinRecycler);
      db= new MyDatabase(this);
      sdb= db.getWritableDatabase();
      mLayoutManager= new LinearLayoutManager(getApplicationContext());
      recycler.setLayoutManager(mLayoutManager);
      mAdapter = new BranchAdapter(getApplicationContext(),Branch.getdata());
      recycler.setAdapter(mAdapter);
  
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main_menu, menu);
      final MenuItem searchItem = menu.findItem(R.id.action_search);
      SearchView search = (SearchView) MenuItemCompat.getActionView(searchItem);
      search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String query) {
              return false;
          }
  
          @Override
          public boolean onQueryTextChange(String newText)
          {
              return false;
          }
      });
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
  
      return super.onOptionsItemSelected(item);
  }
  
  public class BranchAdapter extends RecyclerView.Adapter&lt;BranchAdapter.MyViewHolder&gt; {
  
  
      private Context context;
  
      private ArrayList&lt;BranchInformation&gt; branch;
  
      private LayoutInflater inflater;
      String Name;
  
  
      public BranchAdapter(Context context, ArrayList&lt;BranchInformation&gt; branch) {
          this.context = context;
          this.branch = branch;
          // inflater = LayoutInflater.from(context);
      }
  
      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int position) {
  
          View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.main_card, parent, false);
          MyViewHolder holder = new MyViewHolder(view);
  
          return holder;
      }
  
      @Override
      public void onBindViewHolder(final MyViewHolder myViewHolder, final int position) {
  
          final TextView Title= (TextView)myViewHolder.view.findViewById(R.id.titleText);
          final TextView Pledge= (TextView)myViewHolder.view.findViewById(R.id.pledgedText);
          final TextView Backers= (TextView)myViewHolder.view.findViewById(R.id.backersText);
         // final LinearLayout BranchLayout =(LinearLayout)myViewHolder.view.findViewById(R.id.BranchL);
          Title.setText(branch.get(position).Title);
          Pledge.setText("Pleadge: "+branch.get(position).Pledge+" "+branch.get(position).Currency);
          Backers.setText("Backers: "+branch.get(position).Backers);
  
  
      }
  
      @Override
      public int getItemCount() {
          return branch.size();
      }
  
      class MyViewHolder extends RecyclerView.ViewHolder {
          public View view;
          public MyViewHolder(View itemView) {
              super(itemView);
              view =itemView;
          }
  
  
      }
      // This method adds(duplicates) a Object (item ) to our Branch set as well as Recycler View.
  }
  
  public static class Branch {
  
      public static ArrayList&lt;BranchInformation&gt; getdata() {
          ArrayList&lt;BranchInformation&gt; branch = new ArrayList&lt;BranchInformation&gt;();
          // Select All Query
          try {
              String selectQuery = "SELECT title, amtpledged, numbackers, currency FROM data";
              sdb = db.getWritableDatabase();
  
              Cursor cursor = sdb.rawQuery(selectQuery, null);
              // looping through all rows and adding to list
              if (cursor.moveToFirst()) {
                  do {
                      BranchInformation current = new BranchInformation();
                      current.Title=cursor.getString(0);
                      current.Pledge= cursor.getString(1);
                      current.Backers= cursor.getString(2);
                      current.Currency= cursor.getString(3);
                      branch.add(current);
                  } while (cursor.moveToNext());
              }
          }catch (Exception e) {
              //    Toast.makeText(,"Error Finding data. Please sync to Update Data.", Toast.LENGTH_SHORT).show();}
          }
  
          // return contact list
          return branch;
      }
  }
  
  public static class BranchInformation {
      public String Title;
      public String Pledge;
      public String Backers;
      public String Currency;
  
  
  }
  </code></pre>
  
  <p>}</p>