title: How to implement pagination like whatsApp, messenger Chat page (reverse scroll to load more) using CursorLoader?
body: <p>My OnCreateLoader &amp; onLoadFinished of ChatActivity are:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@Override
      public Loader&lt;Cursor&gt; onCreateLoader(int id, Bundle args) {
  
          CursorLoader loader = new CursorLoader(this,
                  DataProvider.CONTENT_URI_MESSAGES,
                  new String[]{
                      DataProvider.KEY_ID,
                      DataProvider.KEY_PHONE_NUMBER,
                      DataProvider.KEY_USER,
                      DataProvider.KEY_FLAG,
                      DataProvider.KEY_DATE_TIME,
                      DataProvider.KEY_CONTENT
                  },
                  "phone_number=?", new String[]{phoneNo_other}, null);
          return loader;
  
      }
  
      @Override
      public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor data) {
          mChatListBuilderAdapter.swapCursor(data);
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p>This code is working well for whole chatList. But I need to load ex:20 items at first time and on every reverse scroll at top reached load another 20 items to show on list just like WhatsApp.</p>
  
  <p>Is it possible to implement this using rawquery like below? Using below method I got expected data but can't return <code>Loader&lt;Cursor&gt;</code> type data, </p>
  
  <pre><code>public Loader&lt;Cursor&gt; loadInitialItems(String phone_number, int limit){  //// limit 100, 200` -- get 200 records beginning with row 101 //
      SQLiteDatabase db = this.getWritableDatabase();
      String queryToGetInitialData ="SELECT * FROM (SELECT * FROM "+MYDATABASE_TABLE+" WHERE "+KEY_PHONE_NUMBER+" = ? ORDER BY "+KEY_ID+" DESC LIMIT "+limit+") ORDER BY "+KEY_ID+" ASC";
  
      Cursor cursor = db.rawQuery(queryToGetInitialData, new String[] { phone_number });
  
      String chatContent = "";
      if (cursor.moveToFirst()) {
          do {
              chatContent = cursor.getString(cursor.getColumnIndex(DataProvider.KEY_CONTENT));
              Log.d(TAG,"chatContent from DB::"+chatContent);
  
          } while (cursor.moveToNext());
      }
      cursor.close();
      db.close();
  
      return (Loader&lt;Cursor&gt;) cursor; //Problem is here, this return is inappropriate
  }
  </code></pre>
  
  
  
  <p>onScroll to LoadMore mechanism code is like:</p>
  
  <pre><code>messagesList.setOnScrollListener(new AbsListView.OnScrollListener() {
      @Override
      public void onScrollStateChanged(AbsListView view, int scrollState) {
  
      }
  
      @Override
      public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
  
          if(firstVisibleItem+visibleItemCount == totalItemCount &amp;&amp; totalItemCount!=0) {
              if(!flag_loading) {
                  flag_loading = true;
                  loadNextChatItems();
              }
          }
      }
  });
  </code></pre>