title: Grouping Recyclerview items by date with pagination
body: <p>I want to achieve something like : </p>
  
  <pre><code>  17 July,2018
      - item
      - item
    16 July,2018
      - item
      - item
      - item
  </code></pre>
  
  <p>I have achieved this successfully with the following link :</p>
  
  <p><a href="https://stackoverflow.com/q/41447044/8089770">Divide elements on groups in RecyclerView or Grouping Recyclerview items ,say by date</a></p>
  
  <p>But now the problem is in pagination if same date is there in next page also then it will create second header of same date.</p>
  
  <blockquote>
    <p><strong>i.e .</strong>
    if in first page i have data with date 16 July,2018 and in second page also  if i have data continued with date 16 July,2018 then two header are created for both 16 July,2018.</p>
  </blockquote>
  
  <pre><code> Page -1
   17 July,2018
          - item
          - item
   16 July,2018
          - item
          - item
   Page -2
   16 July,2018
          - item
          - item
          - item
          - item
   14 July,2018
          - item
          - item
  </code></pre>
  
  <p><strong>I want all item of one date should be under only one header.. i want to merge two page data if same date..</strong></p>
  
  <p>My code is same as above given link.. still i am adding some important code and if any other code required then please let me know..</p>
  
  <pre><code> private LinkedHashMap&lt;String, List&lt;NotificationData&gt;&gt; groupDataIntoHashMap(List&lt;NotificationData&gt; listOfPojosOfJsonArray) {
  
          LinkedHashMap&lt;String, List&lt;NotificationData&gt;&gt; groupedHashMap = new LinkedHashMap&lt;&gt;();
  
          for (NotificationData pojoOfJsonArray : listOfPojosOfJsonArray) {
  
              String hashMapKey = pojoOfJsonArray.getTicket_date();
  
              if (groupedHashMap.containsKey(hashMapKey)) {
                  // The key is already in the HashMap; add the pojo object
                  // against the existing key.
                  groupedHashMap.get(hashMapKey).add(pojoOfJsonArray);
  
  
              } else {
                  // The key is not there in the HashMap; create a new key-value pair
                  List&lt;NotificationData&gt;  list = new ArrayList&lt;&gt;();
                  list.add(pojoOfJsonArray);
                  groupedHashMap.put(hashMapKey, list);
  
              }
          }
  
          return groupedHashMap;
      }
  </code></pre>
  
  <p>Inside service success :</p>
  
  <pre><code> try {
              JSONObject object = new JSONObject(response);
              if (!Utils.isEmptyString(response)) {
                  if (id == reqIdNotificationList) {
  
                      if (object.getInt(PARAMS.TAG_STATUS) == PARAMS.SUCCESS_STATUS) {
                          String resultArray = object.getString(PARAMS.TAG_RESULT);
                          if (!Utils.isEmptyString(resultArray)) {
  
                              Type listType = new TypeToken&lt;List&lt;NotificationData&gt;&gt;() {
                              }.getType();
                              ArrayList&lt;NotificationData&gt; tmpNotification = new Gson().fromJson(resultArray, listType);
  
  
                              if (tmpNotificationList != null)
                                  tmpNotificationList = new ArrayList&lt;&gt;();
  
                              if (TextUtils.isEmpty(mtktNo)) {
  
                                  tmpNotificationList.clear();
                                  tmpNotificationList.addAll(tmpNotification);
  
                                  LinkedHashMap&lt;String, List&lt;NotificationData&gt;&gt; groupedHashMap = groupDataIntoHashMap(tmpNotificationList);
  
  
                                  for (String date : groupedHashMap.keySet()) {
                                      dateItem = new DateItem();
                                      dateItem.setTicket_date(date);
                                      consolidatedList.add(dateItem);
  
  
                                      for (NotificationData pojoOfJsonArray : groupedHashMap.get(date)) {
                                          generalItem = new GeneralItem();
                                          generalItem.setResult(pojoOfJsonArray);
                                          consolidatedList.add(generalItem);
  
                                      }
  
                                  }
                                  adapter = new NotificationListAdapter(this, consolidatedList, this);
                                  rvNotification.setAdapter(adapter);
  
  //                                notificationList.addAll(tmpNotificationList);
  //                                adapter = new NotificationListAdapter(NotificationActivity.this, notificationList, this);
  //                                rvNotification.setAdapter(adapter);
  
                              } else {
  
                                  int startIndex = tmpNotification.size();
                                  tmpNotificationList.addAll(tmpNotification);
  
                                  Log.d("size",tmpNotificationList.size()+"");
  
                                 adapter.notifyItemRangeInserted(startIndex, tmpNotificationList.size() - 1);
  
                                  LinkedHashMap&lt;String, List&lt;NotificationData&gt;&gt; groupedHashMap = groupDataIntoHashMap(tmpNotificationList);
  
                                  for (String date : groupedHashMap.keySet()) {
                                      DateItem dateItem = new DateItem();
                                      dateItem.setTicket_date(date);
                                      consolidatedList.add(dateItem);
  
  
                                      for (NotificationData pojoOfJsonArray : groupedHashMap.get(date)) {
                                          GeneralItem generalItem = new GeneralItem();
                                          generalItem.setResult(pojoOfJsonArray);
                                          consolidatedList.add(generalItem);
                                      }
                                  }
  
                                  if (consolidatedList.size() &gt;= object.getInt(PARAMS.TAG_RECORD)) {
                                      rvNotification.removeMoreListener();
                                  }
  
  
                              }
                              if (tmpNotificationList.isEmpty()) hideMenu();
                          }
                      }
                  }
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
  </code></pre>
  
  <p>Note : In given link it is hashmap but i have used linked hashmap to maintain item order. </p>
  
  <p>Also i have used this <a href="https://stackoverflow.com/a/33822747/8089770">linear layout manager</a>.</p>
  
  <p>Thank you !</p>